N1QL Query Performance Issue - Declines on volume of data fetch

I am using N1QL query on 60K records with separate indexes on individual predicates and combined index on all predicates plus the metrics as ‘majorindex’ plus I have Primary key index as well.
I am querying 2 years of data with Performance with ~5 seconds performance and it declines to 12 seconds if I do 8 years .

As my dataset is not huge number of records can I get milliseconds perf on 7 years data ? and what is advice to improve if we can… because the total dataset will be millions later at some point of time… Here is how the plan looks like :

{
  "#operator": "Sequence",
  "#stats": {
    "#phaseSwitches": 1,
    "execTime": "1.928µs"
  },
  "~children": [
    {
      "#operator": "Authorize",
      "#stats": {
        "#phaseSwitches": 3,
        "execTime": "2.423µs",
        "servTime": "4.847605ms"
      },
      "privileges": {
        "List": [
          {
            "Target": "default:group360all",
            "Priv": 7
          }
        ]
      },
      "~child": {
        "#operator": "Sequence",
        "#stats": {
          "#phaseSwitches": 1,
          "execTime": "2.215µs"
        },
        "~children": [
          {
            "#operator": "Sequence",
            "#stats": {
              "#phaseSwitches": 1,
              "execTime": "3.063µs"
            },
            "~children": [
              {
                "#operator": "Sequence",
                "#stats": {
                  "#phaseSwitches": 1,
                  "execTime": "1.443µs"
                },
                "~children": [
                  {
                    "#operator": "IndexScan3",
                    "#stats": {
                      "#itemsOut": 49659,
                      "#phaseSwitches": 198639,
                      "execTime": "141.225012ms",
                      "kernTime": "70.753111ms",
                      "servTime": "233.212792ms"
                    },
                    "as": "A",
                    "covers": [
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))",
                      "cover ((`A`.`SnapshotDate`))",
                      "cover ((`A`.`BookingStatus`))",
                      "cover ((`A`.`ExternalMarketSegmentId`))",
                      "cover ((`A`.`ExternalBookedById`))",
                      "cover ((`A`.`RevenueType`))",
                      "cover ((`A`.`BlendedEventRevenueTotal`))",
                      "cover ((`A`.`FBRevenueTotal`))",
                      "cover ((`A`.`AVRevTotal`))",
                      "cover ((`A`.`OtherRevTotal`))",
                      "cover ((`A`.`BlendedRoomnightsTotal`))",
                      "cover ((`A`.`BookedSqft`))",
                      "cover ((`A`.`BlendedGuestroomRevenueTotal`))",
                      "cover ((meta(`A`).`id`))"
                    ],
                    "index": "majorindex",
                    "index_id": "9e209fb4e5dc636",
                    "index_projection": {
                      "entry_keys": [
                        0,
                        1,
                        2,
                        3
                      ]
                    },
                    "keyspace": "group360all",
                    "namespace": "default",
                    "spans": [
                      {
                        "exact": true,
                        "range": [
                          {
                            "high": "\"2020-12-31\"",
                            "inclusion": 3,
                            "low": "\"2013-01-01\""
                          }
                        ]
                      }
                    ],
                    "using": "gsi",
                    "#time_normal": "00:00.3744",
                    "#time_absolute": 0.374437804
                  },
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "1.164µs"
                    },
                    "~children": [
                      {
                        "#operator": "Filter",
                        "#stats": {
                          "#itemsIn": 49659,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 146747,
                          "execTime": "92.584995ms",
                          "kernTime": "352.618797ms"
                        },
                        "condition": "((cover ((`A`.`PatternDate`)) between \"2013-01-01\" and \"2020-12-31\") and (cover ((`A`.`BookingStatus`)) in [\"Definite\"]))",
                        "#time_normal": "00:00.0925",
                        "#time_absolute": 0.092584995
                      },
                      {
                        "#operator": "InitialGroup",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 14861,
                          "#phaseSwitches": 77151,
                          "execTime": "242.446105ms",
                          "kernTime": "288.832205ms"
                        },
                        "aggregates": [
                          "max(cover ((`A`.`SnapshotDate`)))"
                        ],
                        "group_keys": [
                          "cover ((`A`.`PatternDate`))",
                          "cover ((`A`.`ExternalBookingId`))"
                        ],
                        "#time_normal": "00:00.2424",
                        "#time_absolute": 0.242446105
                      }
                    ],
                    "#time_normal": "00:00.0000",
                    "#time_absolute": 0.000001164
                  },
                  {
                    "#operator": "IntermediateGroup",
                    "#stats": {
                      "#itemsIn": 14861,
                      "#itemsOut": 14861,
                      "#phaseSwitches": 59447,
                      "execTime": "86.933473ms",
                      "kernTime": "568.319044ms"
                    },
                    "aggregates": [
                      "max(cover ((`A`.`SnapshotDate`)))"
                    ],
                    "group_keys": [
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))"
                    ],
                    "#time_normal": "00:00.0869",
                    "#time_absolute": 0.08693347300000001
                  },
                  {
                    "#operator": "FinalGroup",
                    "#stats": {
                      "#itemsIn": 14861,
                      "#itemsOut": 14861,
                      "#phaseSwitches": 59447,
                      "execTime": "126.191538ms",
                      "kernTime": "10.2519575s"
                    },
                    "aggregates": [
                      "max(cover ((`A`.`SnapshotDate`)))"
                    ],
                    "group_keys": [
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))"
                    ],
                    "#time_normal": "00:00.1261",
                    "#time_absolute": 0.126191538
                  },
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "591ns"
                    },
                    "~children": [
                      {
                        "#operator": "InitialProject",
                        "#stats": {
                          "#itemsIn": 14861,
                          "#itemsOut": 14861,
                          "#phaseSwitches": 44588,
                          "execTime": "137.512707ms",
                          "kernTime": "669.095036ms"
                        },
                        "result_terms": [
                          {
                            "as": "SnapshotDate",
                            "expr": "max(cover ((`A`.`SnapshotDate`)))"
                          },
                          {
                            "as": "ExternalBookingId",
                            "expr": "cover ((`A`.`ExternalBookingId`))"
                          },
                          {
                            "expr": "cover ((`A`.`PatternDate`))"
                          }
                        ],
                        "#time_normal": "00:00.1375",
                        "#time_absolute": 0.137512707
                      },
                      {
                        "#operator": "FinalProject",
                        "#stats": {
                          "#itemsIn": 14861,
                          "#itemsOut": 14861,
                          "#phaseSwitches": 44584,
                          "execTime": "12.843561ms",
                          "kernTime": "9.937198722s"
                        },
                        "#time_normal": "00:00.0128",
                        "#time_absolute": 0.012843561
                      }
                    ],
                    "#time_normal": "00:00",
                    "#time_absolute": 0
                  }
                ],
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.000001443
              },
              {
                "#operator": "Alias",
                "#stats": {
                  "#itemsIn": 14861,
                  "#itemsOut": 14861,
                  "#phaseSwitches": 59447,
                  "execTime": "51.435915ms",
                  "kernTime": "11.086336098s"
                },
                "as": "T",
                "#time_normal": "00:00.0514",
                "#time_absolute": 0.051435915
              },
              {
                "#operator": "Sequence",
                "#stats": {
                  "#phaseSwitches": 1,
                  "execTime": "1.819µs"
                },
                "~children": [
                  {
                    "#operator": "NestedLoopJoin",
                    "#stats": {
                      "#itemsIn": 14861,
                      "#itemsOut": 14861,
                      "#phaseSwitches": 148613,
                      "execTime": "281.358725ms",
                      "kernTime": "11.146701654s"
                    },
                    "alias": "M",
                    "on_clause": "(((cover ((`M`.`ExternalBookingId`)) = (`T`.`ExternalBookingId`)) and (cover ((`M`.`SnapshotDate`)) = (`T`.`SnapshotDate`))) and ((`T`.`PatternDate`) = cover ((`M`.`PatternDate`))))",
                    "~child": {
                      "#operator": "IndexScan3",
                      "#stats": {
                        "#itemsOut": 14861,
                        "#phaseSwitches": 133749,
                        "execTime": "260.568638ms",
                        "kernTime": "30.735006ms",
                        "servTime": "10.117377641s"
                      },
                      "as": "M",
                      "covers": [
                        "cover ((`M`.`PatternDate`))",
                        "cover ((`M`.`ExternalBookingId`))",
                        "cover ((`M`.`SnapshotDate`))",
                        "cover ((`M`.`BookingStatus`))",
                        "cover ((`M`.`ExternalMarketSegmentId`))",
                        "cover ((`M`.`ExternalBookedById`))",
                        "cover ((`M`.`RevenueType`))",
                        "cover ((`M`.`BlendedEventRevenueTotal`))",
                        "cover ((`M`.`FBRevenueTotal`))",
                        "cover ((`M`.`AVRevTotal`))",
                        "cover ((`M`.`OtherRevTotal`))",
                        "cover ((`M`.`BlendedRoomnightsTotal`))",
                        "cover ((`M`.`BookedSqft`))",
                        "cover ((`M`.`BlendedGuestroomRevenueTotal`))",
                        "cover ((meta(`M`).`id`))"
                      ],
                      "index": "majorindex",
                      "index_id": "9e209fb4e5dc636",
                      "index_projection": {
                        "entry_keys": [
                          0,
                          1,
                          2,
                          3,
                          7,
                          8,
                          9,
                          10,
                          11,
                          12,
                          13
                        ],
                        "primary_key": true
                      },
                      "keyspace": "group360all",
                      "namespace": "default",
                      "nested_loop": true,
                      "spans": [
                        {
                          "exact": true,
                          "range": [
                            {
                              "high": "(`T`.`PatternDate`)",
                              "inclusion": 3,
                              "low": "(`T`.`PatternDate`)"
                            },
                            {
                              "high": "(`T`.`ExternalBookingId`)",
                              "inclusion": 3,
                              "low": "(`T`.`ExternalBookingId`)"
                            },
                            {
                              "high": "(`T`.`SnapshotDate`)",
                              "inclusion": 3,
                              "low": "(`T`.`SnapshotDate`)"
                            }
                          ]
                        }
                      ],
                      "using": "gsi"
                    },
                    "#time_normal": "00:00.2813",
                    "#time_absolute": 0.281358725
                  },
                  {
                    "#operator": "InitialGroup",
                    "#stats": {
                      "#itemsIn": 14861,
                      "#itemsOut": 2417,
                      "#phaseSwitches": 34559,
                      "execTime": "721.692756ms",
                      "kernTime": "10.715754821s"
                    },
                    "aggregates": [
                      "sum(case when (cover ((`M`.`BookingStatus`)) = \"Definite\") then cover ((`M`.`BlendedRoomnightsTotal`)) else 0 end)",
                      "sum(cover ((`M`.`AVRevTotal`)))",
                      "sum(cover ((`M`.`BlendedEventRevenueTotal`)))",
                      "sum(cover ((`M`.`BlendedGuestroomRevenueTotal`)))",
                      "sum(cover ((`M`.`BlendedRoomnightsTotal`)))",
                      "sum(cover ((`M`.`BookedSqft`)))",
                      "sum(cover ((`M`.`FBRevenueTotal`)))",
                      "sum(cover ((`M`.`OtherRevTotal`)))"
                    ],
                    "group_keys": [
                      "cover ((`M`.`PatternDate`))"
                    ],
                    "#time_normal": "00:00.7216",
                    "#time_absolute": 0.721692756
                  }
                ],
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.0000018189999999999999
              },
              {
                "#operator": "IntermediateGroup",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9671,
                  "execTime": "11.308748ms",
                  "kernTime": "11.560802913s"
                },
                "aggregates": [
                  "sum(case when (cover ((`M`.`BookingStatus`)) = \"Definite\") then cover ((`M`.`BlendedRoomnightsTotal`)) else 0 end)",
                  "sum(cover ((`M`.`AVRevTotal`)))",
                  "sum(cover ((`M`.`BlendedEventRevenueTotal`)))",
                  "sum(cover ((`M`.`BlendedGuestroomRevenueTotal`)))",
                  "sum(cover ((`M`.`BlendedRoomnightsTotal`)))",
                  "sum(cover ((`M`.`BookedSqft`)))",
                  "sum(cover ((`M`.`FBRevenueTotal`)))",
                  "sum(cover ((`M`.`OtherRevTotal`)))"
                ],
                "group_keys": [
                  "cover ((`M`.`PatternDate`))"
                ],
                "#time_normal": "00:00.0113",
                "#time_absolute": 0.011308748
              },
              {
                "#operator": "FinalGroup",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9671,
                  "execTime": "141.56248ms",
                  "kernTime": "11.501624877s"
                },
                "aggregates": [
                  "sum(case when (cover ((`M`.`BookingStatus`)) = \"Definite\") then cover ((`M`.`BlendedRoomnightsTotal`)) else 0 end)",
                  "sum(cover ((`M`.`AVRevTotal`)))",
                  "sum(cover ((`M`.`BlendedEventRevenueTotal`)))",
                  "sum(cover ((`M`.`BlendedGuestroomRevenueTotal`)))",
                  "sum(cover ((`M`.`BlendedRoomnightsTotal`)))",
                  "sum(cover ((`M`.`BookedSqft`)))",
                  "sum(cover ((`M`.`FBRevenueTotal`)))",
                  "sum(cover ((`M`.`OtherRevTotal`)))"
                ],
                "group_keys": [
                  "cover ((`M`.`PatternDate`))"
                ],
                "#time_normal": "00:00.1415",
                "#time_absolute": 0.14156248
              },
              {
                "#operator": "InitialProject",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9671,
                  "execTime": "76.224233ms",
                  "kernTime": "11.585662899s"
                },
                "result_terms": [
                  {
                    "as": "patterndate",
                    "expr": "cover ((`M`.`PatternDate`))"
                  },
                  {
                    "as": "funcroomrev",
                    "expr": "round(sum(cover ((`M`.`BlendedEventRevenueTotal`))), 2)"
                  },
                  {
                    "as": "fnbrev",
                    "expr": "round(sum(cover ((`M`.`FBRevenueTotal`))), 2)"
                  },
                  {
                    "as": "avrev",
                    "expr": "round(sum(cover ((`M`.`AVRevTotal`))), 2)"
                  },
                  {
                    "as": "otherrev",
                    "expr": "round(sum(cover ((`M`.`OtherRevTotal`))), 2)"
                  },
                  {
                    "as": "funcrevpergrprn",
                    "expr": "round((sum(cover ((`M`.`BlendedEventRevenueTotal`))) / sum(cover ((`M`.`BlendedRoomnightsTotal`)))), 2)"
                  },
                  {
                    "as": "funcrevperbkdsqft",
                    "expr": "round((sum(cover ((`M`.`BlendedEventRevenueTotal`))) / sum(cover ((`M`.`BookedSqft`)))), 2)"
                  },
                  {
                    "as": "funcrevpersqft",
                    "expr": "round((sum(cover ((`M`.`BlendedEventRevenueTotal`))) / 1000), 2)"
                  },
                  {
                    "as": "grprnleadvolume",
                    "expr": "sum(cover ((`M`.`BlendedRoomnightsTotal`)))"
                  },
                  {
                    "as": "conversion",
                    "expr": "round((sum(case when (cover ((`M`.`BookingStatus`)) = \"Definite\") then cover ((`M`.`BlendedRoomnightsTotal`)) else 0 end) / sum(cover ((`M`.`BlendedRoomnightsTotal`)))), 3)"
                  },
                  {
                    "as": "grprn",
                    "expr": "sum(cover ((`M`.`BlendedRoomnightsTotal`)))"
                  },
                  {
                    "as": "grproomrev",
                    "expr": "round(sum(cover ((`M`.`BlendedGuestroomRevenueTotal`))), 2)"
                  },
                  {
                    "as": "grpadr",
                    "expr": "round((sum(cover ((`M`.`BlendedGuestroomRevenueTotal`))) / sum(cover ((`M`.`BlendedRoomnightsTotal`)))), 0)"
                  }
                ],
                "#time_normal": "00:00.0762",
                "#time_absolute": 0.076224233
              }
            ],
            "#time_normal": "00:00.0000",
            "#time_absolute": 0.000003063
          },
          {
            "#operator": "Order",
            "#stats": {
              "#itemsIn": 2417,
              "#itemsOut": 2417,
              "#phaseSwitches": 7256,
              "execTime": "7.502165ms",
              "kernTime": "11.661522773s"
            },
            "sort_terms": [
              {
                "expr": "cover ((`M`.`PatternDate`))"
              }
            ],
            "#time_normal": "00:00.0075",
            "#time_absolute": 0.007502165
          },
          {
            "#operator": "FinalProject",
            "#stats": {
              "#itemsIn": 2417,
              "#itemsOut": 2417,
              "#phaseSwitches": 7252,
              "execTime": "1.846574ms",
              "kernTime": "50.797425ms"
            },
            "#time_normal": "00:00.0018",
            "#time_absolute": 0.001846574
          }
        ],
        "#time_normal": "00:00.0000",
        "#time_absolute": 0.000002215
      },
      "#time_normal": "00:00.0048",
      "#time_absolute": 0.004850027999999999
    },
    {
      "#operator": "Stream",
      "#stats": {
        "#itemsIn": 2417,
        "#itemsOut": 2417,
        "#phaseSwitches": 9671,
        "execTime": "478.605µs",
        "kernTime": "11.726507402s"
      },
      "#time_normal": "00:00.0004",
      "#time_absolute": 0.000478605
    }
  ],
  "~versions": [
    "2.0.0-N1QL",
    "6.0.1-2037-enterprise"
  ],
  "#time_normal": "00:00.0000",
  "#time_absolute": 0.000001928
}

And I have majorindex as :
CREATE INDEX majorindex ON group360all(PatternDate,ExternalBookingId,SnapshotDate,BookingStatus,ExternalMarketSegmentId,ExternalBookedById,RevenueType,BlendedEventRevenueTotal,FBRevenueTotal,AVRevTotal,OtherRevTotal,BlendedRoomnightsTotal,BookedSqft,BlendedGuestroomRevenueTotal)

thanks

You are doing multilevel aggregation, join.

You can try EE version, with Hash join and aggregation, partition.

Also try adjust index. Post the actual query

I am on EE version and this is exact query :

SELECT
             M.PatternDate patterndate,
                         ROUND(SUM(M.BlendedEventRevenueTotal),2) funcroomrev,
                         ROUND(SUM(M.FBRevenueTotal),2) fnbrev,
                         ROUND(SUM(M.AVRevTotal),2) avrev ,
                         ROUND(SUM(M.OtherRevTotal),2) otherrev ,
                     ROUND(SUM(M.BlendedEventRevenueTotal) / SUM(M.BlendedRoomnightsTotal),2) funcrevpergrprn,
             ROUND(SUM(M.BlendedEventRevenueTotal) / SUM(M.BookedSqft),2)  funcrevperbkdsqft,
                         ROUND(SUM(M.BlendedEventRevenueTotal) / 1000,2) funcrevpersqft,
                         SUM(M.BlendedRoomnightsTotal) grprnleadvolume,
                         ROUND(SUM(CASE WHEN M.BookingStatus = 'Definite' THEN M.BlendedRoomnightsTotal  ELSE 0 END) / SUM(M.BlendedRoomnightsTotal),3) conversion,
                         SUM(M.BlendedRoomnightsTotal) grprn,
                         ROUND(SUM(M.BlendedGuestroomRevenueTotal),2) grproomrev,
                         ROUND(SUM(M.BlendedGuestroomRevenueTotal) / SUM(M.BlendedRoomnightsTotal),0) grpadr
                             FROM(
                                 SELECT  MAX(A.SnapshotDate) SnapshotDate,
                                 A.ExternalBookingId  ExternalBookingId,
                                 A.PatternDate
                                 FROM `group360all` A
                                 WHERE A.PatternDate BETWEEN  '2013-01-01'  AND  '2020-12-31'
                                 AND A.BookingStatus IN ['Definite']
                                 GROUP BY A.PatternDate,  A.ExternalBookingId
                             ) T
                             INNER JOIN `group360all` M
                             ON M.ExternalBookingId = T.ExternalBookingId
                             AND M.SnapshotDate = T.SnapshotDate
                             AND T.PatternDate = M.PatternDate
                             GROUP BY M.PatternDate
                             ORDER BY M.PatternDate

Try this. If needed use PARTITION Index.

   SELECT d.PatternDate patterndate,
           ROUND(SUM(v.BlendedEventRevenueTotal),2) funcroomrev,
           ROUND(SUM(v.FBRevenueTotal),2) fnbrev,
           ROUND(SUM(v.AVRevTotal),2) avrev ,
           ROUND(SUM(v.OtherRevTotal),2) otherrev ,
           ROUND(SUM(v.BlendedEventRevenueTotal) / SUM(v.BlendedRoomnightsTotal),2) funcrevpergrprn,
           ROUND(SUM(v.BlendedEventRevenueTotal) / SUM(v.BookedSqft),2) funcrevperbkdsqft,
           ROUND(SUM(v.BlendedEventRevenueTotal) / 1000,2) funcrevpersqft,
           SUM(v.BlendedRoomnightsTotal) grprnleadvolume,
           ROUND(SUM(CASE WHEN v.BookingStatus = 'Definite' THEN v.BlendedRoomnightsTotal ELSE 0 END) / SUM(v.BlendedRoomnightsTotal),3) conversion,
           SUM(v.BlendedRoomnightsTotal) grprn,
           ROUND(SUM(v.BlendedGuestroomRevenueTotal),2) grproomrev,
           ROUND(SUM(v.BlendedGuestroomRevenueTotal) / SUM(v.BlendedRoomnightsTotal),0) grpadr
    FROM ( SELECT A.PatternDate, A.ExternalBookingId, MAX([A.SnapshotDate,A.vals])[1] AS vals
           FROM ( SELECT A.PatternDate, A.ExternalBookingId, A.SnapshotDate,
                         ARRAY_AGG({A.BlendedEventRevenueTotal, A.FBRevenueTotal, A.AVRevTotal,
                                    A.OtherRevTotal, A.BlendedRoomnightsTotal, A.BookedSqft,
                                    A.BlendedGuestroomRevenueTotal, A.BookingStatus}) AS vals
                  FROM group360all A
                  WHERE A.PatternDate BETWEEN '2013-01-01' AND '2020-12-31'
                        AND A.BookingStatus IN ['Definite']
                  GROUP BY A.PatternDate, A.ExternalBookingId, A.SnapshotDate ) AS A
           GROUP BY A.PatternDate, A.ExternalBookingId) AS d
    UNNEST d.vals AS v
    GROUP BY d.PatternDate;

CREATE INDEX ix1 ON group360all(BookingStatus, PatternDate, ExternalBookingId, SnapshotDate,
BlendedEventRevenueTotal, FBRevenueTotal, AVRevTotal, OtherRevTotal, BlendedRoomnightsTotal,
BookedSqft, BlendedGuestroomRevenueTotal);

With mentioned index and change in query it is taking 5-7 seconds response time . Still not good what we want to achieve . Here is the plan .

{
  "#operator": "Sequence",
  "#stats": {
    "#phaseSwitches": 1,
    "execTime": "2.737µs"
  },
  "~children": [
    {
      "#operator": "Authorize",
      "#stats": {
        "#phaseSwitches": 3,
        "execTime": "6.988µs",
        "servTime": "1.803171ms"
      },
      "privileges": {
        "List": [
          {
            "Target": "default:group360all",
            "Priv": 7
          }
        ]
      },
      "~child": {
        "#operator": "Sequence",
        "#stats": {
          "#phaseSwitches": 1,
          "execTime": "4.889µs"
        },
        "~children": [
          {
            "#operator": "Sequence",
            "#stats": {
              "#phaseSwitches": 1,
              "execTime": "2.853µs"
            },
            "~children": [
              {
                "#operator": "Sequence",
                "#stats": {
                  "#phaseSwitches": 1,
                  "execTime": "3.105µs"
                },
                "~children": [
                  {
                    "#operator": "IndexScan3",
                    "#stats": {
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "153.584377ms",
                      "kernTime": "1.191421612s",
                      "servTime": "24.53158ms"
                    },
                    "as": "A",
                    "covers": [
                      "cover ((`A`.`BookingStatus`))",
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))",
                      "cover ((`A`.`SnapshotDate`))",
                      "cover ((`A`.`BlendedEventRevenueTotal`))",
                      "cover ((`A`.`FBRevenueTotal`))",
                      "cover ((`A`.`AVRevTotal`))",
                      "cover ((`A`.`OtherRevTotal`))",
                      "cover ((`A`.`BlendedRoomnightsTotal`))",
                      "cover ((`A`.`BookedSqft`))",
                      "cover ((`A`.`BlendedGuestroomRevenueTotal`))",
                      "cover ((meta(`A`).`id`))"
                    ],
                    "index": "ix1",
                    "index_id": "88844ec9eda42dab",
                    "index_projection": {
                      "entry_keys": [
                        0,
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10
                      ]
                    },
                    "keyspace": "group360all",
                    "namespace": "default",
                    "spans": [
                      {
                        "exact": true,
                        "range": [
                          {
                            "high": "\"Definite\"",
                            "inclusion": 3,
                            "low": "\"Definite\""
                          },
                          {
                            "high": "\"2020-12-31\"",
                            "inclusion": 3,
                            "low": "\"2013-01-01\""
                          }
                        ]
                      }
                    ],
                    "using": "gsi",
                    "#time_normal": "00:00.1781",
                    "#time_absolute": 0.178115957
                  },
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "1.741µs"
                    },
                    "~children": [
                      {
                        "#operator": "Filter",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 94855,
                          "execTime": "179.316742ms",
                          "kernTime": "1.210991189s"
                        },
                        "condition": "((cover ((`A`.`PatternDate`)) between \"2013-01-01\" and \"2020-12-31\") and (cover ((`A`.`BookingStatus`)) in [\"Definite\"]))",
                        "#time_normal": "00:00.1793",
                        "#time_absolute": 0.179316742
                      },
                      {
                        "#operator": "InitialGroup",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 94855,
                          "execTime": "1.391238805s",
                          "kernTime": "224.110826ms"
                        },
                        "aggregates": [
                          "array_agg({\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`))})"
                        ],
                        "group_keys": [
                          "cover ((`A`.`PatternDate`))",
                          "cover ((`A`.`ExternalBookingId`))",
                          "cover ((`A`.`SnapshotDate`))"
                        ],
                        "#time_normal": "00:01.3912",
                        "#time_absolute": 1.391238805
                      }
                    ],
                    "#time_normal": "00:00.0000",
                    "#time_absolute": 0.0000017410000000000001
                  },
                  {
                    "#operator": "IntermediateGroup",
                    "#stats": {
                      "#itemsIn": 23713,
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "206.261485ms",
                      "kernTime": "2.188942214s"
                    },
                    "aggregates": [
                      "array_agg({\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`))})"
                    ],
                    "group_keys": [
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))",
                      "cover ((`A`.`SnapshotDate`))"
                    ],
                    "#time_normal": "00:00.2062",
                    "#time_absolute": 0.206261485
                  },
                  {
                    "#operator": "FinalGroup",
                    "#stats": {
                      "#itemsIn": 23713,
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "765.333485ms",
                      "kernTime": "2.539939972s"
                    },
                    "aggregates": [
                      "array_agg({\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`))})"
                    ],
                    "group_keys": [
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))",
                      "cover ((`A`.`SnapshotDate`))"
                    ],
                    "#time_normal": "00:00.7653",
                    "#time_absolute": 0.765333485
                  },
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "1.005µs"
                    },
                    "~children": [
                      {
                        "#operator": "InitialProject",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 71144,
                          "execTime": "630.505342ms",
                          "kernTime": "2.414618177s"
                        },
                        "result_terms": [
                          {
                            "expr": "cover ((`A`.`PatternDate`))"
                          },
                          {
                            "expr": "cover ((`A`.`ExternalBookingId`))"
                          },
                          {
                            "expr": "cover ((`A`.`SnapshotDate`))"
                          },
                          {
                            "as": "vals",
                            "expr": "array_agg({\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`))})"
                          }
                        ],
                        "#time_normal": "00:00.6305",
                        "#time_absolute": 0.6305053420000001
                      },
                      {
                        "#operator": "FinalProject",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 71140,
                          "execTime": "93.34192ms",
                          "kernTime": "172.84768ms"
                        },
                        "#time_normal": "00:00.0933",
                        "#time_absolute": 0.09334192
                      }
                    ],
                    "#time_normal": "00:00.0000",
                    "#time_absolute": 0.000001005
                  }
                ],
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.000003105
              },
              {
                "#operator": "Alias",
                "#stats": {
                  "#itemsIn": 23713,
                  "#itemsOut": 23713,
                  "#phaseSwitches": 94855,
                  "execTime": "55.646916ms",
                  "kernTime": "3.268321319s"
                },
                "as": "A",
                "#time_normal": "00:00.0556",
                "#time_absolute": 0.055646916
              },
              {
                "#operator": "InitialGroup",
                "#stats": {
                  "#itemsIn": 23713,
                  "#itemsOut": 14861,
                  "#phaseSwitches": 77151,
                  "execTime": "918.915037ms",
                  "kernTime": "2.50878522s"
                },
                "aggregates": [
                  "max([(`A`.`SnapshotDate`), (`A`.`vals`)])"
                ],
                "group_keys": [
                  "(`A`.`PatternDate`)",
                  "(`A`.`ExternalBookingId`)"
                ],
                "#time_normal": "00:00.9189",
                "#time_absolute": 0.918915037
              },
              {
                "#operator": "IntermediateGroup",
                "#stats": {
                  "#itemsIn": 14861,
                  "#itemsOut": 14861,
                  "#phaseSwitches": 59447,
                  "execTime": "97.688574ms",
                  "kernTime": "3.544044642s"
                },
                "aggregates": [
                  "max([(`A`.`SnapshotDate`), (`A`.`vals`)])"
                ],
                "group_keys": [
                  "(`A`.`PatternDate`)",
                  "(`A`.`ExternalBookingId`)"
                ],
                "#time_normal": "00:00.0976",
                "#time_absolute": 0.097688574
              },
              {
                "#operator": "FinalGroup",
                "#stats": {
                  "#itemsIn": 14861,
                  "#itemsOut": 14861,
                  "#phaseSwitches": 59447,
                  "execTime": "212.386059ms",
                  "kernTime": "4.195494505s"
                },
                "aggregates": [
                  "max([(`A`.`SnapshotDate`), (`A`.`vals`)])"
                ],
                "group_keys": [
                  "(`A`.`PatternDate`)",
                  "(`A`.`ExternalBookingId`)"
                ],
                "#time_normal": "00:00.2123",
                "#time_absolute": 0.212386059
              },
              {
                "#operator": "Sequence",
                "#stats": {
                  "#phaseSwitches": 1,
                  "execTime": "1.15µs"
                },
                "~children": [
                  {
                    "#operator": "InitialProject",
                    "#stats": {
                      "#itemsIn": 14861,
                      "#itemsOut": 14861,
                      "#phaseSwitches": 44588,
                      "execTime": "152.007308ms",
                      "kernTime": "3.654137295s"
                    },
                    "result_terms": [
                      {
                        "expr": "(`A`.`PatternDate`)"
                      },
                      {
                        "expr": "(`A`.`ExternalBookingId`)"
                      },
                      {
                        "as": "vals",
                        "expr": "(max([(`A`.`SnapshotDate`), (`A`.`vals`)])[1])"
                      }
                    ],
                    "#time_normal": "00:00.1520",
                    "#time_absolute": 0.152007308
                  },
                  {
                    "#operator": "FinalProject",
                    "#stats": {
                      "#itemsIn": 14861,
                      "#itemsOut": 14861,
                      "#phaseSwitches": 44584,
                      "execTime": "6.916701ms",
                      "kernTime": "613.556857ms"
                    },
                    "#time_normal": "00:00.0069",
                    "#time_absolute": 0.006916701
                  }
                ],
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.00000115
              }
            ],
            "#time_normal": "00:00.0000",
            "#time_absolute": 0.000002853
          },
          {
            "#operator": "Alias",
            "#stats": {
              "#itemsIn": 14861,
              "#itemsOut": 14861,
              "#phaseSwitches": 59447,
              "execTime": "16.756787ms",
              "kernTime": "4.434117235s"
            },
            "as": "d",
            "#time_normal": "00:00.0167",
            "#time_absolute": 0.016756787
          },
          {
            "#operator": "Unnest",
            "#stats": {
              "#itemsIn": 14861,
              "#itemsOut": 14861,
              "#phaseSwitches": 59447,
              "execTime": "52.628596ms",
              "kernTime": "4.418841993s"
            },
            "as": "v",
            "expr": "(`d`.`vals`)",
            "#time_normal": "00:00.0526",
            "#time_absolute": 0.052628596
          },
          {
            "#operator": "InitialGroup",
            "#stats": {
              "#itemsIn": 14861,
              "#itemsOut": 2417,
              "#phaseSwitches": 34559,
              "execTime": "832.736847ms",
              "kernTime": "3.67273874s"
            },
            "aggregates": [
              "sum((`v`.`AVRevTotal`))",
              "sum((`v`.`BlendedEventRevenueTotal`))",
              "sum((`v`.`BlendedGuestroomRevenueTotal`))",
              "sum((`v`.`BlendedRoomnightsTotal`))",
              "sum((`v`.`BookedSqft`))",
              "sum((`v`.`FBRevenueTotal`))",
              "sum((`v`.`OtherRevTotal`))",
              "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
            ],
            "group_keys": [
              "(`d`.`PatternDate`)"
            ],
            "#time_normal": "00:00.8327",
            "#time_absolute": 0.8327368470000001
          },
          {
            "#operator": "IntermediateGroup",
            "#stats": {
              "#itemsIn": 2417,
              "#itemsOut": 2417,
              "#phaseSwitches": 9671,
              "execTime": "14.489429ms",
              "kernTime": "4.576420311s"
            },
            "aggregates": [
              "sum((`v`.`AVRevTotal`))",
              "sum((`v`.`BlendedEventRevenueTotal`))",
              "sum((`v`.`BlendedGuestroomRevenueTotal`))",
              "sum((`v`.`BlendedRoomnightsTotal`))",
              "sum((`v`.`BookedSqft`))",
              "sum((`v`.`FBRevenueTotal`))",
              "sum((`v`.`OtherRevTotal`))",
              "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
            ],
            "group_keys": [
              "(`d`.`PatternDate`)"
            ],
            "#time_normal": "00:00.0144",
            "#time_absolute": 0.014489429
          },
          {
            "#operator": "FinalGroup",
            "#stats": {
              "#itemsIn": 2417,
              "#itemsOut": 2417,
              "#phaseSwitches": 9671,
              "execTime": "138.424305ms",
              "kernTime": "4.774683405s"
            },
            "aggregates": [
              "sum((`v`.`AVRevTotal`))",
              "sum((`v`.`BlendedEventRevenueTotal`))",
              "sum((`v`.`BlendedGuestroomRevenueTotal`))",
              "sum((`v`.`BlendedRoomnightsTotal`))",
              "sum((`v`.`BookedSqft`))",
              "sum((`v`.`FBRevenueTotal`))",
              "sum((`v`.`OtherRevTotal`))",
              "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
            ],
            "group_keys": [
              "(`d`.`PatternDate`)"
            ],
            "#time_normal": "00:00.1384",
            "#time_absolute": 0.138424305
          },
          {
            "#operator": "Sequence",
            "#stats": {
              "#phaseSwitches": 1,
              "execTime": "3.877µs"
            },
            "~children": [
              {
                "#operator": "InitialProject",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 7256,
                  "execTime": "282.063917ms",
                  "kernTime": "4.650296078s"
                },
                "result_terms": [
                  {
                    "as": "patterndate",
                    "expr": "(`d`.`PatternDate`)"
                  },
                  {
                    "as": "funcroomrev",
                    "expr": "round(sum((`v`.`BlendedEventRevenueTotal`)), 2)"
                  },
                  {
                    "as": "fnbrev",
                    "expr": "round(sum((`v`.`FBRevenueTotal`)), 2)"
                  },
                  {
                    "as": "avrev",
                    "expr": "round(sum((`v`.`AVRevTotal`)), 2)"
                  },
                  {
                    "as": "otherrev",
                    "expr": "round(sum((`v`.`OtherRevTotal`)), 2)"
                  },
                  {
                    "as": "funcrevpergrprn",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / sum((`v`.`BlendedRoomnightsTotal`))), 2)"
                  },
                  {
                    "as": "funcrevperbkdsqft",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / sum((`v`.`BookedSqft`))), 2)"
                  },
                  {
                    "as": "funcrevpersqft",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / 1000), 2)"
                  },
                  {
                    "as": "grprnleadvolume",
                    "expr": "sum((`v`.`BlendedRoomnightsTotal`))"
                  },
                  {
                    "as": "conversion",
                    "expr": "round((sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end) / sum((`v`.`BlendedRoomnightsTotal`))), 3)"
                  },
                  {
                    "as": "grprn",
                    "expr": "sum((`v`.`BlendedRoomnightsTotal`))"
                  },
                  {
                    "as": "grproomrev",
                    "expr": "round(sum((`v`.`BlendedGuestroomRevenueTotal`)), 2)"
                  },
                  {
                    "as": "grpadr",
                    "expr": "round((sum((`v`.`BlendedGuestroomRevenueTotal`)) / sum((`v`.`BlendedRoomnightsTotal`))), 0)"
                  }
                ],
                "#time_normal": "00:00.2820",
                "#time_absolute": 0.282063917
              },
              {
                "#operator": "FinalProject",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 7252,
                  "execTime": "8.090162ms",
                  "kernTime": "19.730124ms"
                },
                "#time_normal": "00:00.0080",
                "#time_absolute": 0.008090162
              }
            ],
            "#time_normal": "00:00.0000",
            "#time_absolute": 0.0000038769999999999995
          }
        ],
        "#time_normal": "00:00.0000",
        "#time_absolute": 0.000004889
      },
      "#time_normal": "00:00.0018",
      "#time_absolute": 0.0018101590000000002
    },
    {
      "#operator": "Stream",
      "#stats": {
        "#itemsIn": 2417,
        "#itemsOut": 2417,
        "#phaseSwitches": 9671,
        "execTime": "973.489µs",
        "kernTime": "4.961687068s"
      },
      "#time_normal": "00:00.0009",
      "#time_absolute": 0.000973489
    }
  ],
  "~versions": [
    "2.0.0-N1QL",
    "6.0.1-2037-enterprise"
  ],
  "#time_normal": "00:00.0000",
  "#time_absolute": 0.0000027370000000000002
}

You can use partition index, max_prallelsim

Based on the output it looks like A.PatternDate, A.ExternalBookingId, A.SnapshotDate combination has single document. Is that true. If yes you can avoid ARRAY_AGG() and later UNNEST.

Make sure all the fields in PARTITION are immutable.

CREATE INDEX ix1 ON group360all(BookingStatus, PatternDate, ExternalBookingId, SnapshotDate,
BlendedEventRevenueTotal, FBRevenueTotal, AVRevTotal, OtherRevTotal, BlendedRoomnightsTotal,
BookedSqft, BlendedGuestroomRevenueTotal) PARTITION BY HASH(BookingStatus, PatternDate, ExternalBookingId, SnapshotDate);

SELECT v.PatternDate patterndate,
       ROUND(SUM(v.BlendedEventRevenueTotal),2) funcroomrev,
       ROUND(SUM(v.FBRevenueTotal),2) fnbrev,
       ROUND(SUM(v.AVRevTotal),2) avrev ,
       ROUND(SUM(v.OtherRevTotal),2) otherrev ,
       ROUND(SUM(v.BlendedEventRevenueTotal) / SUM(v.BlendedRoomnightsTotal),2) funcrevpergrprn,
       ROUND(SUM(v.BlendedEventRevenueTotal) / SUM(v.BookedSqft),2) funcrevperbkdsqft,
       ROUND(SUM(v.BlendedEventRevenueTotal) / 1000,2) funcrevpersqft,
       SUM(v.BlendedRoomnightsTotal) grprnleadvolume,
       ROUND(SUM(CASE WHEN v.BookingStatus = 'Definite' THEN v.BlendedRoomnightsTotal ELSE 0 END) / SUM(v.BlendedRoomnightsTotal),3) conversion,
       SUM(v.BlendedRoomnightsTotal) grprn,
       ROUND(SUM(v.BlendedGuestroomRevenueTotal),2) grproomrev,
       ROUND(SUM(v.BlendedGuestroomRevenueTotal) / SUM(v.BlendedRoomnightsTotal),0) grpadr
FROM ( SELECT RAW MAX ([A.SnapshotDate, {A.PatternDate, A.ExternalBookingId, A.SnapshotDate ,
                                A.BlendedEventRevenueTotal, A.FBRevenueTotal, A.AVRevTotal,
                                A.OtherRevTotal, A.BlendedRoomnightsTotal, A.BookedSqft,
                                A.BlendedGuestroomRevenueTotal, A.BookingStatus}])[1]
       FROM group360all A
       WHERE A.PatternDate BETWEEN '2013-01-01' AND '2020-12-31'
             AND A.BookingStatus IN ['Definite']
       GROUP BY A.PatternDate, A.ExternalBookingId, A.SnapshotDate ) AS v
GROUP BY v.PatternDate
ORDER BY v.PatternDate;
1 Like

Yes those attributes in single document and this time with Partition Index performance goes back to worse : 9 Secs …
And some execution we are getting Unexepected Server errors not sure if this related to partition Index .

I have other index as well for other query and I hope that is not conflicting with ix1 :
Here is other one :
CREATE INDEX majorindex ON group360all(PatternDate,ExternalBookingId,SnapshotDate,BookingStatus,ExternalMarketSegmentId,ExternalBookedById,RevenueType,BlendedEventRevenueTotal,FBRevenueTotal,AVRevTotal,OtherRevTotal,BlendedRoomnightsTotal,BookedSqft,BlendedGuestroomRevenueTotal)

Here is new PLAN :

{
  "#operator": "Sequence",
  "#stats": {
    "#phaseSwitches": 1,
    "execTime": "3.784µs"
  },
  "~children": [
    {
      "#operator": "Authorize",
      "#stats": {
        "#phaseSwitches": 3,
        "execTime": "3.503µs",
        "servTime": "6.569139ms"
      },
      "privileges": {
        "List": [
          {
            "Target": "default:group360all",
            "Priv": 7
          }
        ]
      },
      "~child": {
        "#operator": "Sequence",
        "#stats": {
          "#phaseSwitches": 1,
          "execTime": "2.526µs"
        },
        "~children": [
          {
            "#operator": "Sequence",
            "#stats": {
              "#phaseSwitches": 1,
              "execTime": "3.906µs"
            },
            "~children": [
              {
                "#operator": "Sequence",
                "#stats": {
                  "#phaseSwitches": 1,
                  "execTime": "2.656µs"
                },
                "~children": [
                  {
                    "#operator": "IndexScan3",
                    "#stats": {
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "90.864499ms",
                      "kernTime": "4.735261995s",
                      "servTime": "111.94964ms"
                    },
                    "as": "A",
                    "index": "ix1",
                    "index_id": "52c26893e43df195",
                    "index_projection": {
                      "primary_key": true
                    },
                    "keyspace": "group360all",
                    "namespace": "default",
                    "spans": [
                      {
                        "exact": true,
                        "range": [
                          {
                            "high": "\"Definite\"",
                            "inclusion": 3,
                            "low": "\"Definite\""
                          },
                          {
                            "high": "\"2020-12-31\"",
                            "inclusion": 3,
                            "low": "\"2013-01-01\""
                          }
                        ]
                      }
                    ],
                    "using": "gsi",
                    "#time_normal": "00:00.2028",
                    "#time_absolute": 0.202814139
                  },
                  {
                    "#operator": "Fetch",
                    "#stats": {
                      "#itemsIn": 23713,
                      "#itemsOut": 23713,
                      "#phaseSwitches": 97821,
                      "execTime": "104.137166ms",
                      "kernTime": "1.59918112s",
                      "servTime": "3.395997925s"
                    },
                    "as": "A",
                    "keyspace": "group360all",
                    "namespace": "default",
                    "#time_normal": "00:03.5001",
                    "#time_absolute": 3.500135091
                  },
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "1.163µs"
                    },
                    "~children": [
                      {
                        "#operator": "Filter",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 94855,
                          "execTime": "5.050006685s",
                          "kernTime": "164.085669ms"
                        },
                        "condition": "(((`A`.`PatternDate`) between \"2013-01-01\" and \"2020-12-31\") and ((`A`.`BookingStatus`) in [\"Definite\"]))",
                        "#time_normal": "00:05.0500",
                        "#time_absolute": 5.050006685
                      },
                      {
                        "#operator": "InitialGroup",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 94855,
                          "execTime": "3.558994451s",
                          "kernTime": "1.970543698s"
                        },
                        "aggregates": [
                          "max([(`A`.`SnapshotDate`), `A`])"
                        ],
                        "group_keys": [
                          "(`A`.`PatternDate`)",
                          "(`A`.`ExternalBookingId`)",
                          "(`A`.`SnapshotDate`)"
                        ],
                        "#time_normal": "00:03.5589",
                        "#time_absolute": 3.558994451
                      }
                    ],
                    "#time_normal": "00:00.0000",
                    "#time_absolute": 0.0000011630000000000001
                  },
                  {
                    "#operator": "IntermediateGroup",
                    "#stats": {
                      "#itemsIn": 23713,
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "296.245671ms",
                      "kernTime": "5.892441786s"
                    },
                    "aggregates": [
                      "max([(`A`.`SnapshotDate`), `A`])"
                    ],
                    "group_keys": [
                      "(`A`.`PatternDate`)",
                      "(`A`.`ExternalBookingId`)",
                      "(`A`.`SnapshotDate`)"
                    ],
                    "#time_normal": "00:00.2962",
                    "#time_absolute": 0.296245671
                  },
                  {
                    "#operator": "FinalGroup",
                    "#stats": {
                      "#itemsIn": 23713,
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "600.525914ms",
                      "kernTime": "7.06502274s"
                    },
                    "aggregates": [
                      "max([(`A`.`SnapshotDate`), `A`])"
                    ],
                    "group_keys": [
                      "(`A`.`PatternDate`)",
                      "(`A`.`ExternalBookingId`)",
                      "(`A`.`SnapshotDate`)"
                    ],
                    "#time_normal": "00:00.6005",
                    "#time_absolute": 0.600525914
                  },
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "518ns"
                    },
                    "~children": [
                      {
                        "#operator": "InitialProject",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 71144,
                          "execTime": "186.059955ms",
                          "kernTime": "6.20910972s"
                        },
                        "raw": true,
                        "result_terms": [
                          {
                            "expr": "(max([(`A`.`SnapshotDate`), `A`])[1])"
                          }
                        ],
                        "#time_normal": "00:00.1860",
                        "#time_absolute": 0.186059955
                      },
                      {
                        "#operator": "FinalProject",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 71140,
                          "execTime": "7.475297ms",
                          "kernTime": "1.299185532s"
                        },
                        "#time_normal": "00:00.0074",
                        "#time_absolute": 0.0074752970000000005
                      }
                    ],
                    "#time_normal": "00:00",
                    "#time_absolute": 0
                  }
                ],
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.000002656
              },
              {
                "#operator": "Alias",
                "#stats": {
                  "#itemsIn": 23713,
                  "#itemsOut": 23713,
                  "#phaseSwitches": 94855,
                  "execTime": "49.563367ms",
                  "kernTime": "7.690685609s"
                },
                "as": "v",
                "#time_normal": "00:00.0495",
                "#time_absolute": 0.049563367
              },
              {
                "#operator": "InitialGroup",
                "#stats": {
                  "#itemsIn": 23713,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 52263,
                  "execTime": "1.550716288s",
                  "kernTime": "6.233051994s"
                },
                "aggregates": [
                  "sum((`v`.`AVRevTotal`))",
                  "sum((`v`.`BlendedEventRevenueTotal`))",
                  "sum((`v`.`BlendedGuestroomRevenueTotal`))",
                  "sum((`v`.`BlendedRoomnightsTotal`))",
                  "sum((`v`.`BookedSqft`))",
                  "sum((`v`.`FBRevenueTotal`))",
                  "sum((`v`.`OtherRevTotal`))",
                  "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
                ],
                "group_keys": [
                  "(`v`.`PatternDate`)"
                ],
                "#time_normal": "00:01.5507",
                "#time_absolute": 1.550716288
              },
              {
                "#operator": "IntermediateGroup",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9671,
                  "execTime": "14.729302ms",
                  "kernTime": "7.870369283s"
                },
                "aggregates": [
                  "sum((`v`.`AVRevTotal`))",
                  "sum((`v`.`BlendedEventRevenueTotal`))",
                  "sum((`v`.`BlendedGuestroomRevenueTotal`))",
                  "sum((`v`.`BlendedRoomnightsTotal`))",
                  "sum((`v`.`BookedSqft`))",
                  "sum((`v`.`FBRevenueTotal`))",
                  "sum((`v`.`OtherRevTotal`))",
                  "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
                ],
                "group_keys": [
                  "(`v`.`PatternDate`)"
                ],
                "#time_normal": "00:00.0147",
                "#time_absolute": 0.014729302000000001
              },
              {
                "#operator": "FinalGroup",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9671,
                  "execTime": "113.527615ms",
                  "kernTime": "7.91906684s"
                },
                "aggregates": [
                  "sum((`v`.`AVRevTotal`))",
                  "sum((`v`.`BlendedEventRevenueTotal`))",
                  "sum((`v`.`BlendedGuestroomRevenueTotal`))",
                  "sum((`v`.`BlendedRoomnightsTotal`))",
                  "sum((`v`.`BookedSqft`))",
                  "sum((`v`.`FBRevenueTotal`))",
                  "sum((`v`.`OtherRevTotal`))",
                  "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
                ],
                "group_keys": [
                  "(`v`.`PatternDate`)"
                ],
                "#time_normal": "00:00.1135",
                "#time_absolute": 0.113527615
              },
              {
                "#operator": "InitialProject",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9673,
                  "execTime": "151.599547ms",
                  "kernTime": "7.909318269s"
                },
                "result_terms": [
                  {
                    "as": "patterndate",
                    "expr": "(`v`.`PatternDate`)"
                  },
                  {
                    "as": "funcroomrev",
                    "expr": "round(sum((`v`.`BlendedEventRevenueTotal`)), 2)"
                  },
                  {
                    "as": "fnbrev",
                    "expr": "round(sum((`v`.`FBRevenueTotal`)), 2)"
                  },
                  {
                    "as": "avrev",
                    "expr": "round(sum((`v`.`AVRevTotal`)), 2)"
                  },
                  {
                    "as": "otherrev",
                    "expr": "round(sum((`v`.`OtherRevTotal`)), 2)"
                  },
                  {
                    "as": "funcrevpergrprn",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / sum((`v`.`BlendedRoomnightsTotal`))), 2)"
                  },
                  {
                    "as": "funcrevperbkdsqft",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / sum((`v`.`BookedSqft`))), 2)"
                  },
                  {
                    "as": "funcrevpersqft",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / 1000), 2)"
                  },
                  {
                    "as": "grprnleadvolume",
                    "expr": "sum((`v`.`BlendedRoomnightsTotal`))"
                  },
                  {
                    "as": "conversion",
                    "expr": "round((sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end) / sum((`v`.`BlendedRoomnightsTotal`))), 3)"
                  },
                  {
                    "as": "grprn",
                    "expr": "sum((`v`.`BlendedRoomnightsTotal`))"
                  },
                  {
                    "as": "grproomrev",
                    "expr": "round(sum((`v`.`BlendedGuestroomRevenueTotal`)), 2)"
                  },
                  {
                    "as": "grpadr",
                    "expr": "round((sum((`v`.`BlendedGuestroomRevenueTotal`)) / sum((`v`.`BlendedRoomnightsTotal`))), 0)"
                  }
                ],
                "#time_normal": "00:00.1515",
                "#time_absolute": 0.151599547
              }
            ],
            "#time_normal": "00:00.0000",
            "#time_absolute": 0.000003906
          },
          {
            "#operator": "Order",
            "#stats": {
              "#itemsIn": 2417,
              "#itemsOut": 2417,
              "#phaseSwitches": 7256,
              "execTime": "34.206134ms",
              "kernTime": "8.060291449s"
            },
            "sort_terms": [
              {
                "expr": "(`v`.`PatternDate`)"
              }
            ],
            "#time_normal": "00:00.0342",
            "#time_absolute": 0.034206134
          },
          {
            "#operator": "FinalProject",
            "#stats": {
              "#itemsIn": 2417,
              "#itemsOut": 2417,
              "#phaseSwitches": 7252,
              "execTime": "2.110367ms",
              "kernTime": "50.07089ms"
            },
            "#time_normal": "00:00.0021",
            "#time_absolute": 0.002110367
          }
        ],
        "#time_normal": "00:00.0000",
        "#time_absolute": 0.0000025259999999999996
      },
      "#time_normal": "00:00.0065",
      "#time_absolute": 0.006572642
    },
    {
      "#operator": "Stream",
      "#stats": {
        "#itemsIn": 2417,
        "#itemsOut": 2417,
        "#phaseSwitches": 9671,
        "execTime": "397.355µs",
        "kernTime": "8.153305356s"
      },
      "#time_normal": "00:00.0003",
      "#time_absolute": 0.000397355
    }
  ],
  "~versions": [
    "2.0.0-N1QL",
    "6.0.1-2037-enterprise"
  ],
  "#time_normal": "00:00.0000",
  "#time_absolute": 0.0000037839999999999997
}

It doing Fetch. Updated query in previous post try again.

Yes , goes back to 4 -5 seconds … Here is updated PLAN :

{
  "#operator": "Sequence",
  "#stats": {
    "#phaseSwitches": 1,
    "execTime": "1.91µs"
  },
  "~children": [
    {
      "#operator": "Authorize",
      "#stats": {
        "#phaseSwitches": 3,
        "execTime": "4.547µs",
        "servTime": "100.958512ms"
      },
      "privileges": {
        "List": [
          {
            "Target": "default:group360all",
            "Priv": 7
          }
        ]
      },
      "~child": {
        "#operator": "Sequence",
        "#stats": {
          "#phaseSwitches": 1,
          "execTime": "4.041µs"
        },
        "~children": [
          {
            "#operator": "Sequence",
            "#stats": {
              "#phaseSwitches": 1,
              "execTime": "6.149µs"
            },
            "~children": [
              {
                "#operator": "Sequence",
                "#stats": {
                  "#phaseSwitches": 1,
                  "execTime": "2.93µs"
                },
                "~children": [
                  {
                    "#operator": "IndexScan3",
                    "#stats": {
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "136.785674ms",
                      "kernTime": "900.41736ms",
                      "servTime": "861.136455ms"
                    },
                    "as": "A",
                    "covers": [
                      "cover ((`A`.`BookingStatus`))",
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))",
                      "cover ((`A`.`SnapshotDate`))",
                      "cover ((`A`.`BlendedEventRevenueTotal`))",
                      "cover ((`A`.`FBRevenueTotal`))",
                      "cover ((`A`.`AVRevTotal`))",
                      "cover ((`A`.`OtherRevTotal`))",
                      "cover ((`A`.`BlendedRoomnightsTotal`))",
                      "cover ((`A`.`BookedSqft`))",
                      "cover ((`A`.`BlendedGuestroomRevenueTotal`))",
                      "cover ((meta(`A`).`id`))",
                      "cover (max([cover ((`A`.`SnapshotDate`)), {\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"ExternalBookingId\": cover ((`A`.`ExternalBookingId`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`)), \"PatternDate\": cover ((`A`.`PatternDate`)), \"SnapshotDate\": cover ((`A`.`SnapshotDate`))}]))"
                    ],
                    "index": "ix1",
                    "index_group_aggs": {
                      "aggregates": [
                        {
                          "aggregate": "MAX",
                          "depends": [
                            0,
                            1,
                            2,
                            3,
                            4,
                            5,
                            6,
                            7,
                            8,
                            9,
                            10
                          ],
                          "expr": "[cover ((`A`.`SnapshotDate`)), {\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"ExternalBookingId\": cover ((`A`.`ExternalBookingId`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`)), \"PatternDate\": cover ((`A`.`PatternDate`)), \"SnapshotDate\": cover ((`A`.`SnapshotDate`))}]",
                          "id": 12,
                          "keypos": -1
                        }
                      ],
                      "depends": [
                        0,
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10
                      ],
                      "group": [
                        {
                          "depends": [
                            1
                          ],
                          "expr": "cover ((`A`.`PatternDate`))",
                          "id": 1,
                          "keypos": 1
                        },
                        {
                          "depends": [
                            2
                          ],
                          "expr": "cover ((`A`.`ExternalBookingId`))",
                          "id": 2,
                          "keypos": 2
                        },
                        {
                          "depends": [
                            3
                          ],
                          "expr": "cover ((`A`.`SnapshotDate`))",
                          "id": 3,
                          "keypos": 3
                        }
                      ],
                      "partial": true
                    },
                    "index_id": "52c26893e43df195",
                    "index_projection": {
                      "entry_keys": [
                        1,
                        2,
                        3,
                        12
                      ]
                    },
                    "keyspace": "group360all",
                    "namespace": "default",
                    "spans": [
                      {
                        "exact": true,
                        "range": [
                          {
                            "high": "\"Definite\"",
                            "inclusion": 3,
                            "low": "\"Definite\""
                          },
                          {
                            "high": "\"2020-12-31\"",
                            "inclusion": 3,
                            "low": "\"2013-01-01\""
                          }
                        ]
                      }
                    ],
                    "using": "gsi",
                    "#time_normal": "00:00.9979",
                    "#time_absolute": 0.9979221289999999
                  },
                  {
                    "#operator": "InitialGroup",
                    "#stats": {
                      "#itemsIn": 23713,
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "1.493477873s",
                      "kernTime": "635.530726ms"
                    },
                    "aggregates": [
                      "max(cover (max([cover ((`A`.`SnapshotDate`)), {\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"ExternalBookingId\": cover ((`A`.`ExternalBookingId`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`)), \"PatternDate\": cover ((`A`.`PatternDate`)), \"SnapshotDate\": cover ((`A`.`SnapshotDate`))}])))"
                    ],
                    "group_keys": [
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))",
                      "cover ((`A`.`SnapshotDate`))"
                    ],
                    "#time_normal": "00:01.4934",
                    "#time_absolute": 1.493477873
                  },
                  {
                    "#operator": "IntermediateGroup",
                    "#stats": {
                      "#itemsIn": 23713,
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "228.391044ms",
                      "kernTime": "2.397780071s"
                    },
                    "aggregates": [
                      "max(cover (max([cover ((`A`.`SnapshotDate`)), {\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"ExternalBookingId\": cover ((`A`.`ExternalBookingId`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`)), \"PatternDate\": cover ((`A`.`PatternDate`)), \"SnapshotDate\": cover ((`A`.`SnapshotDate`))}])))"
                    ],
                    "group_keys": [
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))",
                      "cover ((`A`.`SnapshotDate`))"
                    ],
                    "#time_normal": "00:00.2283",
                    "#time_absolute": 0.228391044
                  },
                  {
                    "#operator": "FinalGroup",
                    "#stats": {
                      "#itemsIn": 23713,
                      "#itemsOut": 23713,
                      "#phaseSwitches": 94855,
                      "execTime": "462.721726ms",
                      "kernTime": "3.459121726s"
                    },
                    "aggregates": [
                      "max(cover (max([cover ((`A`.`SnapshotDate`)), {\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"ExternalBookingId\": cover ((`A`.`ExternalBookingId`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`)), \"PatternDate\": cover ((`A`.`PatternDate`)), \"SnapshotDate\": cover ((`A`.`SnapshotDate`))}])))"
                    ],
                    "group_keys": [
                      "cover ((`A`.`PatternDate`))",
                      "cover ((`A`.`ExternalBookingId`))",
                      "cover ((`A`.`SnapshotDate`))"
                    ],
                    "#time_normal": "00:00.4627",
                    "#time_absolute": 0.462721726
                  },
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "1.445µs"
                    },
                    "~children": [
                      {
                        "#operator": "InitialProject",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 71144,
                          "execTime": "164.415758ms",
                          "kernTime": "2.642706803s"
                        },
                        "raw": true,
                        "result_terms": [
                          {
                            "expr": "(max(cover (max([cover ((`A`.`SnapshotDate`)), {\"AVRevTotal\": cover ((`A`.`AVRevTotal`)), \"BlendedEventRevenueTotal\": cover ((`A`.`BlendedEventRevenueTotal`)), \"BlendedGuestroomRevenueTotal\": cover ((`A`.`BlendedGuestroomRevenueTotal`)), \"BlendedRoomnightsTotal\": cover ((`A`.`BlendedRoomnightsTotal`)), \"BookedSqft\": cover ((`A`.`BookedSqft`)), \"BookingStatus\": cover ((`A`.`BookingStatus`)), \"ExternalBookingId\": cover ((`A`.`ExternalBookingId`)), \"FBRevenueTotal\": cover ((`A`.`FBRevenueTotal`)), \"OtherRevTotal\": cover ((`A`.`OtherRevTotal`)), \"PatternDate\": cover ((`A`.`PatternDate`)), \"SnapshotDate\": cover ((`A`.`SnapshotDate`))}])))[1])"
                          }
                        ],
                        "#time_normal": "00:00.1644",
                        "#time_absolute": 0.16441575800000002
                      },
                      {
                        "#operator": "FinalProject",
                        "#stats": {
                          "#itemsIn": 23713,
                          "#itemsOut": 23713,
                          "#phaseSwitches": 71140,
                          "execTime": "10.630925ms",
                          "kernTime": "1.12365123s"
                        },
                        "#time_normal": "00:00.0106",
                        "#time_absolute": 0.010630925
                      }
                    ],
                    "#time_normal": "00:00.0000",
                    "#time_absolute": 0.0000014450000000000001
                  }
                ],
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.0000029300000000000003
              },
              {
                "#operator": "Alias",
                "#stats": {
                  "#itemsIn": 23713,
                  "#itemsOut": 23713,
                  "#phaseSwitches": 94855,
                  "execTime": "38.32392ms",
                  "kernTime": "3.929407943s"
                },
                "as": "v",
                "#time_normal": "00:00.0383",
                "#time_absolute": 0.038323920000000004
              },
              {
                "#operator": "InitialGroup",
                "#stats": {
                  "#itemsIn": 23713,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 52263,
                  "execTime": "1.339497722s",
                  "kernTime": "2.662484797s"
                },
                "aggregates": [
                  "sum((`v`.`AVRevTotal`))",
                  "sum((`v`.`BlendedEventRevenueTotal`))",
                  "sum((`v`.`BlendedGuestroomRevenueTotal`))",
                  "sum((`v`.`BlendedRoomnightsTotal`))",
                  "sum((`v`.`BookedSqft`))",
                  "sum((`v`.`FBRevenueTotal`))",
                  "sum((`v`.`OtherRevTotal`))",
                  "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
                ],
                "group_keys": [
                  "(`v`.`PatternDate`)"
                ],
                "#time_normal": "00:01.3394",
                "#time_absolute": 1.339497722
              },
              {
                "#operator": "IntermediateGroup",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9671,
                  "execTime": "12.960975ms",
                  "kernTime": "4.089028676s"
                },
                "aggregates": [
                  "sum((`v`.`AVRevTotal`))",
                  "sum((`v`.`BlendedEventRevenueTotal`))",
                  "sum((`v`.`BlendedGuestroomRevenueTotal`))",
                  "sum((`v`.`BlendedRoomnightsTotal`))",
                  "sum((`v`.`BookedSqft`))",
                  "sum((`v`.`FBRevenueTotal`))",
                  "sum((`v`.`OtherRevTotal`))",
                  "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
                ],
                "group_keys": [
                  "(`v`.`PatternDate`)"
                ],
                "#time_normal": "00:00.0129",
                "#time_absolute": 0.012960975
              },
              {
                "#operator": "FinalGroup",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9671,
                  "execTime": "110.210366ms",
                  "kernTime": "4.122744728s"
                },
                "aggregates": [
                  "sum((`v`.`AVRevTotal`))",
                  "sum((`v`.`BlendedEventRevenueTotal`))",
                  "sum((`v`.`BlendedGuestroomRevenueTotal`))",
                  "sum((`v`.`BlendedRoomnightsTotal`))",
                  "sum((`v`.`BookedSqft`))",
                  "sum((`v`.`FBRevenueTotal`))",
                  "sum((`v`.`OtherRevTotal`))",
                  "sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end)"
                ],
                "group_keys": [
                  "(`v`.`PatternDate`)"
                ],
                "#time_normal": "00:00.1102",
                "#time_absolute": 0.11021036599999999
              },
              {
                "#operator": "InitialProject",
                "#stats": {
                  "#itemsIn": 2417,
                  "#itemsOut": 2417,
                  "#phaseSwitches": 9671,
                  "execTime": "132.258371ms",
                  "kernTime": "4.123852546s"
                },
                "result_terms": [
                  {
                    "as": "patterndate",
                    "expr": "(`v`.`PatternDate`)"
                  },
                  {
                    "as": "funcroomrev",
                    "expr": "round(sum((`v`.`BlendedEventRevenueTotal`)), 2)"
                  },
                  {
                    "as": "fnbrev",
                    "expr": "round(sum((`v`.`FBRevenueTotal`)), 2)"
                  },
                  {
                    "as": "avrev",
                    "expr": "round(sum((`v`.`AVRevTotal`)), 2)"
                  },
                  {
                    "as": "otherrev",
                    "expr": "round(sum((`v`.`OtherRevTotal`)), 2)"
                  },
                  {
                    "as": "funcrevpergrprn",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / sum((`v`.`BlendedRoomnightsTotal`))), 2)"
                  },
                  {
                    "as": "funcrevperbkdsqft",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / sum((`v`.`BookedSqft`))), 2)"
                  },
                  {
                    "as": "funcrevpersqft",
                    "expr": "round((sum((`v`.`BlendedEventRevenueTotal`)) / 1000), 2)"
                  },
                  {
                    "as": "grprnleadvolume",
                    "expr": "sum((`v`.`BlendedRoomnightsTotal`))"
                  },
                  {
                    "as": "conversion",
                    "expr": "round((sum(case when ((`v`.`BookingStatus`) = \"Definite\") then (`v`.`BlendedRoomnightsTotal`) else 0 end) / sum((`v`.`BlendedRoomnightsTotal`))), 3)"
                  },
                  {
                    "as": "grprn",
                    "expr": "sum((`v`.`BlendedRoomnightsTotal`))"
                  },
                  {
                    "as": "grproomrev",
                    "expr": "round(sum((`v`.`BlendedGuestroomRevenueTotal`)), 2)"
                  },
                  {
                    "as": "grpadr",
                    "expr": "round((sum((`v`.`BlendedGuestroomRevenueTotal`)) / sum((`v`.`BlendedRoomnightsTotal`))), 0)"
                  }
                ],
                "#time_normal": "00:00.1322",
                "#time_absolute": 0.132258371
              }
            ],
            "#time_normal": "00:00.0000",
            "#time_absolute": 0.000006149
          },
          {
            "#operator": "Order",
            "#stats": {
              "#itemsIn": 2417,
              "#itemsOut": 2417,
              "#phaseSwitches": 7256,
              "execTime": "9.501542ms",
              "kernTime": "4.255668209s"
            },
            "sort_terms": [
              {
                "expr": "(`v`.`PatternDate`)"
              }
            ],
            "#time_normal": "00:00.0095",
            "#time_absolute": 0.009501542
          },
          {
            "#operator": "FinalProject",
            "#stats": {
              "#itemsIn": 2417,
              "#itemsOut": 2417,
              "#phaseSwitches": 7252,
              "execTime": "2.21984ms",
              "kernTime": "47.905072ms"
            },
            "#time_normal": "00:00.0022",
            "#time_absolute": 0.00221984
          }
        ],
        "#time_normal": "00:00.0000",
        "#time_absolute": 0.000004041000000000001
      },
      "#time_normal": "00:00.1009",
      "#time_absolute": 0.100963059
    },
    {
      "#operator": "Stream",
      "#stats": {
        "#itemsIn": 2417,
        "#itemsOut": 2417,
        "#phaseSwitches": 9671,
        "execTime": "510.672µs",
        "kernTime": "4.416188647s"
      },
      "#time_normal": "00:00.0005",
      "#time_absolute": 0.000510672
    }
  ],
  "~versions": [
    "2.0.0-N1QL",
    "6.0.1-2037-enterprise"
  ],
  "#time_normal": "00:00.0000",
  "#time_absolute": 0.00000191
}

A.BookingStatus is always one value you can add that inner most query GROUP KEY
GROUP BY A.PatternDate, A.ExternalBookingId, A.SnapshotDate, A.BookingStatus

in this example its one value but ideally we will be passing multiple values through In clause from user interface … what I still didn’t get is that for fetching the records within 50K document limit if this is scale of performance in CB its being not a good use experience . We are doing POC’s and assessing to work on multiple databases . In relational context Oracle don’t even take more than second so why CB can’t …
Note I am not adding any extra indexes unless you told me … Also I had several other indexes on each predicates separately … I assume those are not counter forbiding the perf we want to gain as Explain plan doesn’t show those Index names .

@vsr1 Hi , to conclude thread are you saying we can’t get any better performance than this :
This is trimmed down version of similar query : performance 2.4 seconds + .
Here is explain plan :

    {
      "#operator": "Sequence",
      "#stats": {
        "#phaseSwitches": 1,
        "execTime": "1.902µs"
      },
      "~children": [
        {
          "#operator": "Authorize",
          "#stats": {
            "#phaseSwitches": 3,
            "execTime": "2.629µs",
            "servTime": "1.421358ms"
          },
          "privileges": {
            "List": [
              {
                "Target": "default:group360all",
                "Priv": 7
              }
            ]
          },
          "~child": {
            "#operator": "Sequence",
            "#stats": {
              "#phaseSwitches": 1,
              "execTime": "1.565µs"
            },
            "~children": [
              {
                "#operator": "Sequence",
                "#stats": {
                  "#phaseSwitches": 1,
                  "execTime": "2.092µs"
                },
                "~children": [
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "1.216µs"
                    },
                    "~children": [
                      {
                        "#operator": "IndexScan3",
                        "#stats": {
                          "#itemsOut": 3440,
                          "#phaseSwitches": 13763,
                          "execTime": "12.318117ms",
                          "kernTime": "1.218809712s",
                          "servTime": "10.034907ms"
                        },
                        "as": "A",
                        "covers": [
                          "cover ((`A`.`PatternDate`))",
                          "cover ((`A`.`ExternalBookingId`))",
                          "cover ((`A`.`SnapshotDate`))",
                          "cover ((`A`.`MealPeriod`))",
                          "cover ((`A`.`BookingStatus`))",
                          "cover ((`A`.`ExternalMarketSegmentId`))",
                          "cover ((`A`.`ExternalBookedById`))",
                          "cover ((`A`.`RevenueType`))",
                          "cover ((`A`.`BlendedEventRevenueTotal`))",
                          "cover ((`A`.`FBRevenueTotal`))",
                          "cover ((`A`.`AVRevTotal`))",
                          "cover ((`A`.`OtherRevTotal`))",
                          "cover ((`A`.`BlendedRoomnightsTotal`))",
                          "cover ((`A`.`BookedSqft`))",
                          "cover ((`A`.`BlendedGuestroomRevenueTotal`))",
                          "cover ((meta(`A`).`id`))",
                          "cover (max(cover ((`A`.`SnapshotDate`))))"
                        ],
                        "index": "majorindex",
                        "index_group_aggs": {
                          "aggregates": [
                            {
                              "aggregate": "MAX",
                              "depends": [
                                2
                              ],
                              "expr": "cover ((`A`.`SnapshotDate`))",
                              "id": 16,
                              "keypos": 2
                            }
                          ],
                          "depends": [
                            0,
                            1,
                            2
                          ],
                          "group": [
                            {
                              "depends": [
                                0
                              ],
                              "expr": "cover ((`A`.`PatternDate`))",
                              "id": 0,
                              "keypos": 0
                            },
                            {
                              "depends": [
                                1
                              ],
                              "expr": "cover ((`A`.`ExternalBookingId`))",
                              "id": 1,
                              "keypos": 1
                            }
                          ]
                        },
                        "index_id": "d97408f73cff3999",
                        "index_projection": {
                          "entry_keys": [
                            0,
                            1,
                            16
                          ]
                        },
                        "keyspace": "group360all",
                        "namespace": "default",
                        "spans": [
                          {
                            "exact": true,
                            "range": [
                              {
                                "high": "\"2018-12-31\"",
                                "inclusion": 3,
                                "low": "\"2018-01-01\""
                              }
                            ]
                          }
                        ],
                        "using": "gsi",
                        "#time_normal": "00:00.0223",
                        "#time_absolute": 0.022353024000000003
                      },
                      {
                        "#operator": "Sequence",
                        "#stats": {
                          "#phaseSwitches": 1,
                          "execTime": "480ns"
                        },
                        "~children": [
                          {
                            "#operator": "InitialProject",
                            "#stats": {
                              "#itemsIn": 3440,
                              "#itemsOut": 3440,
                              "#phaseSwitches": 10325,
                              "execTime": "17.273411ms",
                              "kernTime": "5.544406ms"
                            },
                            "result_terms": [
                              {
                                "as": "SnapshotDate",
                                "expr": "cover (max(cover ((`A`.`SnapshotDate`))))"
                              },
                              {
                                "as": "ExternalBookingId",
                                "expr": "cover ((`A`.`ExternalBookingId`))"
                              },
                              {
                                "expr": "cover ((`A`.`PatternDate`))"
                              }
                            ],
                            "#time_normal": "00:00.0172",
                            "#time_absolute": 0.017273411
                          },
                          {
                            "#operator": "FinalProject",
                            "#stats": {
                              "#itemsIn": 3440,
                              "#itemsOut": 3440,
                              "#phaseSwitches": 10321,
                              "execTime": "2.715931ms",
                              "kernTime": "1.717338203s"
                            },
                            "#time_normal": "00:00.0027",
                            "#time_absolute": 0.002715931
                          }
                        ],
                        "#time_normal": "00:00",
                        "#time_absolute": 0
                      }
                    ],
                    "#time_normal": "00:00.0000",
                    "#time_absolute": 0.0000012159999999999999
                  },
                  {
                    "#operator": "Alias",
                    "#stats": {
                      "#itemsIn": 3440,
                      "#itemsOut": 3440,
                      "#phaseSwitches": 13763,
                      "execTime": "10.128594ms",
                      "kernTime": "2.01497758s"
                    },
                    "as": "T",
                    "#time_normal": "00:00.0101",
                    "#time_absolute": 0.010128594
                  },
                  {
                    "#operator": "Sequence",
                    "#stats": {
                      "#phaseSwitches": 1,
                      "execTime": "1.436µs"
                    },
                    "~children": [
                      {
                        "#operator": "NestedLoopJoin",
                        "#stats": {
                          "#itemsIn": 3440,
                          "#itemsOut": 3440,
                          "#phaseSwitches": 34403,
                          "execTime": "43.658231ms",
                          "kernTime": "2.42588051s"
                        },
                        "alias": "M",
                        "on_clause": "(((cover ((`M`.`ExternalBookingId`)) = (`T`.`ExternalBookingId`)) and (cover ((`M`.`SnapshotDate`)) = (`T`.`SnapshotDate`))) and ((`T`.`PatternDate`) = cover ((`M`.`PatternDate`))))",
                        "~child": {
                          "#operator": "IndexScan3",
                          "#stats": {
                            "#itemsOut": 3440,
                            "#phaseSwitches": 30960,
                            "execTime": "45.285679ms",
                            "kernTime": "7.512994ms",
                            "servTime": "2.351739429s"
                          },
                          "as": "M",
                          "covers": [
                            "cover ((`M`.`PatternDate`))",
                            "cover ((`M`.`ExternalBookingId`))",
                            "cover ((`M`.`SnapshotDate`))",
                            "cover ((`M`.`MealPeriod`))",
                            "cover ((`M`.`BookingStatus`))",
                            "cover ((`M`.`ExternalMarketSegmentId`))",
                            "cover ((`M`.`ExternalBookedById`))",
                            "cover ((`M`.`RevenueType`))",
                            "cover ((`M`.`BlendedEventRevenueTotal`))",
                            "cover ((`M`.`FBRevenueTotal`))",
                            "cover ((`M`.`AVRevTotal`))",
                            "cover ((`M`.`OtherRevTotal`))",
                            "cover ((`M`.`BlendedRoomnightsTotal`))",
                            "cover ((`M`.`BookedSqft`))",
                            "cover ((`M`.`BlendedGuestroomRevenueTotal`))",
                            "cover ((meta(`M`).`id`))"
                          ],
                          "index": "majorindex",
                          "index_id": "d97408f73cff3999",
                          "index_projection": {
                            "entry_keys": [
                              0,
                              1,
                              2,
                              4,
                              12
                            ],
                            "primary_key": true
                          },
                          "keyspace": "group360all",
                          "namespace": "default",
                          "nested_loop": true,
                          "spans": [
                            {
                              "exact": true,
                              "range": [
                                {
                                  "high": "(`T`.`PatternDate`)",
                                  "inclusion": 3,
                                  "low": "(`T`.`PatternDate`)"
                                },
                                {
                                  "high": "(`T`.`ExternalBookingId`)",
                                  "inclusion": 3,
                                  "low": "(`T`.`ExternalBookingId`)"
                                },
                                {
                                  "high": "(`T`.`SnapshotDate`)",
                                  "inclusion": 3,
                                  "low": "(`T`.`SnapshotDate`)"
                                }
                              ]
                            }
                          ],
                          "using": "gsi"
                        },
                        "#time_normal": "00:00.0436",
                        "#time_absolute": 0.043658231
                      },
                      {
                        "#operator": "InitialGroup",
                        "#stats": {
                          "#itemsIn": 3440,
                          "#itemsOut": 6,
                          "#phaseSwitches": 6895,
                          "execTime": "107.292013ms",
                          "kernTime": "2.362280804s"
                        },
                        "aggregates": [
                          "sum(case when (cover ((`M`.`BookingStatus`)) = \"Definite\") then cover ((`M`.`BlendedRoomnightsTotal`)) else 0 end)",
                          "sum(cover ((`M`.`BlendedRoomnightsTotal`)))"
                        ],
                        "group_keys": [
                          "cover ((`M`.`BookingStatus`))"
                        ],
                        "#time_normal": "00:00.1072",
                        "#time_absolute": 0.10729201299999999
                      }
                    ],
                    "#time_normal": "00:00.0000",
                    "#time_absolute": 0.0000014359999999999999
                  },
                  {
                    "#operator": "IntermediateGroup",
                    "#stats": {
                      "#itemsIn": 6,
                      "#itemsOut": 6,
                      "#phaseSwitches": 27,
                      "execTime": "47.897µs",
                      "kernTime": "2.469582958s"
                    },
                    "aggregates": [
                      "sum(case when (cover ((`M`.`BookingStatus`)) = \"Definite\") then cover ((`M`.`BlendedRoomnightsTotal`)) else 0 end)",
                      "sum(cover ((`M`.`BlendedRoomnightsTotal`)))"
                    ],
                    "group_keys": [
                      "cover ((`M`.`BookingStatus`))"
                    ],
                    "#time_normal": "00:00.0000",
                    "#time_absolute": 0.000047897
                  },
                  {
                    "#operator": "FinalGroup",
                    "#stats": {
                      "#itemsIn": 6,
                      "#itemsOut": 6,
                      "#phaseSwitches": 27,
                      "execTime": "100.125µs",
                      "kernTime": "2.469639619s"
                    },
                    "aggregates": [
                      "sum(case when (cover ((`M`.`BookingStatus`)) = \"Definite\") then cover ((`M`.`BlendedRoomnightsTotal`)) else 0 end)",
                      "sum(cover ((`M`.`BlendedRoomnightsTotal`)))"
                    ],
                    "group_keys": [
                      "cover ((`M`.`BookingStatus`))"
                    ],
                    "#time_normal": "00:00.0001",
                    "#time_absolute": 0.000100125
                  },
                  {
                    "#operator": "InitialProject",
                    "#stats": {
                      "#itemsIn": 6,
                      "#itemsOut": 6,
                      "#phaseSwitches": 27,
                      "execTime": "115.148µs",
                      "kernTime": "2.469747886s"
                    },
                    "result_terms": [
                      {
                        "as": "bookingstatus",
                        "expr": "cover ((`M`.`BookingStatus`))"
                      },
                      {
                        "as": "grprnleadvolume",
                        "expr": "sum(cover ((`M`.`BlendedRoomnightsTotal`)))"
                      },
                      {
                        "as": "bookingstatusorder",
                        "expr": "case when (cover ((`M`.`BookingStatus`)) = \"Turned Down\") then 1 when (cover ((`M`.`BookingStatus`)) = \"Lost\") then 2 when (cover ((`M`.`BookingStatus`)) = \"Prospect\") then 3 when (cover ((`M`.`BookingStatus`)) = \"Tentative\") then 4 when (cover ((`M`.`BookingStatus`)) = \"Definite\") then 5 when (cover ((`M`.`BookingStatus`)) = \"Cancelled\") then 6 else 7 end"
                      },
                      {
                        "as": "conversion",
                        "expr": "round((sum(case when (cover ((`M`.`BookingStatus`)) = \"Definite\") then cover ((`M`.`BlendedRoomnightsTotal`)) else 0 end) / sum(cover ((`M`.`BlendedRoomnightsTotal`)))), 3)"
                      }
                    ],
                    "#time_normal": "00:00.0001",
                    "#time_absolute": 0.000115148
                  }
                ],
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.000002092
              },
              {
                "#operator": "Order",
                "#stats": {
                  "#itemsIn": 6,
                  "#itemsOut": 6,
                  "#phaseSwitches": 23,
                  "execTime": "30.743µs",
                  "kernTime": "2.469870296s"
                },
                "sort_terms": [
                  {
                    "expr": "`bookingstatusorder`"
                  }
                ],
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.000030743
              },
              {
                "#operator": "FinalProject",
                "#stats": {
                  "#itemsIn": 6,
                  "#itemsOut": 6,
                  "#phaseSwitches": 19,
                  "execTime": "5.438µs",
                  "kernTime": "88.029µs"
                },
                "#time_normal": "00:00.0000",
                "#time_absolute": 0.0000054379999999999994
              }
            ],
            "#time_normal": "00:00.0000",
            "#time_absolute": 0.000001565
          },
          "#time_normal": "00:00.0014",
          "#time_absolute": 0.001423987
        },
        {
          "#operator": "Stream",
          "#stats": {
            "#itemsIn": 6,
            "#itemsOut": 6,
            "#phaseSwitches": 27,
            "execTime": "5.037µs",
            "kernTime": "2.471428212s"
          },
          "#time_normal": "00:00.0000",
          "#time_absolute": 0.000005037
        }
      ],
      "~versions": [
        "2.0.0-N1QL",
        "6.0.1-2037-enterprise"
      ],
      "#time_normal": "00:00.0000",
      "#time_absolute": 0.000001902
    }


SELECT
             M.BookingStatus  bookingstatus,
             SUM(M.BlendedRoomnightsTotal) grprnleadvolume,
                 (CASE WHEN M.BookingStatus = 'Turned Down' THEN 1
             WHEN M.BookingStatus = 'Lost' THEN 2
             WHEN M.BookingStatus = 'Prospect' THEN 3
             WHEN M.BookingStatus = 'Tentative' THEN 4
             WHEN M.BookingStatus = 'Definite' THEN 5
             WHEN M.BookingStatus = 'Cancelled' THEN 6 ELSE 7 END ) bookingstatusorder ,
             ROUND(SUM(CASE WHEN M.BookingStatus = 'Definite' THEN M.BlendedRoomnightsTotal  ELSE 0 END) / SUM(M.BlendedRoomnightsTotal),3)  conversion
                            FROM(
                                 SELECT  MAX(A.SnapshotDate) SnapshotDate,
                                 A.ExternalBookingId  ExternalBookingId,
                                 A.PatternDate
                                 FROM `group360all` A
                                 WHERE A.PatternDate BETWEEN  '2018-01-01'  AND  '2018-12-31'
                                 GROUP BY A.PatternDate,  A.ExternalBookingId
                                ) T
                                INNER JOIN `group360all` M
            ON M.ExternalBookingId = T.ExternalBookingId
            AND M.SnapshotDate = T.SnapshotDate
            AND T.PatternDate = M.PatternDate
            GROUP BY M.BookingStatus
            ORDER BY bookingstatusorder asc
SELECT
     M.BookingStatus bookingstatus,
     SUM(M.BlendedRoomnightsTotal) grprnleadvolume,
     (CASE WHEN M.BookingStatus = "Turned Down" THEN 1
           WHEN M.BookingStatus = "Lost" THEN 2
           WHEN M.BookingStatus = "Prospect" THEN 3
           WHEN M.BookingStatus = "Tentative" THEN 4
           WHEN M.BookingStatus = "Definite" THEN 5
           WHEN M.BookingStatus = "Cancelled" THEN 6 ELSE 7 END ) bookingstatusorder ,
     ROUND(SUM(CASE WHEN M.BookingStatus = "Definite" THEN M.BlendedRoomnightsTotal ELSE 0 END) / SUM(M.BlendedRoomnightsTotal),3) conversion
FROM ( SELECT mx.*
       FROM group360all AS A
       WHERE A.PatternDate BETWEEN "2018-01-01" AND "2018-12-31"
       GROUP BY A.PatternDate, A.ExternalBookingId
       LETTING mx = MAX([A.SnapshotDate, {A.BookingStatus, A.BlendedRoomnightsTotal}])[1]
    ) M
GROUP BY M.BookingStatus
ORDER BY bookingstatusorder ASC
1 Like

@vsr1 This is Definitely getting better performance in ms now … But can you help me understand the logic here and how this is helping ignoring the INNER JOINS …

Also does this same logic can be applied in all other queries . For e.g I want to transform this one taking 2 secs+ . But my data results and grain seems to be messed up .So I am sure I am missing something.

SELECT
M.PatternDate patterndate,
ROUND(SUM(M.BlendedEventRevenueTotal),2) funcroomrev,
ROUND(SUM(M.FBRevenueTotal),2) fnbrev,
ROUND(SUM(M.AVRevTotal),2) avrev ,
ROUND(SUM(M.OtherRevTotal),2) otherrev ,
ROUND(SUM(M.BlendedEventRevenueTotal) / SUM(M.BlendedRoomnightsTotal),2) funcrevpergrprn,
ROUND(SUM(M.BlendedEventRevenueTotal) / SUM(M.BookedSqft),2) funcrevperbkdsqft,
ROUND(SUM(M.BlendedEventRevenueTotal) / 100,2) funcrevpersqft,
SUM(M.BlendedRoomnightsTotal) grprnleadvolume,
ROUND(SUM(CASE WHEN M.BookingStatus = ‘Definite’ THEN M.BlendedRoomnightsTotal ELSE 0 END) / SUM(M.BlendedRoomnightsTotal),3) conversion,
SUM(M.BlendedRoomnightsTotal) grprn,
ROUND(SUM(M.BlendedGuestroomRevenueTotal),2) grproomrev,
ROUND(SUM(M.BlendedGuestroomRevenueTotal) / SUM(M.BlendedRoomnightsTotal),0) grpadr
FROM(
SELECT MAX(A.SnapshotDate) SnapshotDate,
A.ExternalBookingId ExternalBookingId,
A.PatternDate
FROM group360all A
WHERE A.PatternDate BETWEEN ‘2018-01-01’ AND ‘2018-12-31’
AND A.BookingStatus IN [‘Definite’]
GROUP BY A.PatternDate, A.ExternalBookingId
) T
INNER JOIN group360all M
ON M.ExternalBookingId = T.ExternalBookingId
AND M.SnapshotDate = T.SnapshotDate
AND T.PatternDate = M.PatternDate
GROUP BY M.PatternDate
ORDER BY M.PatternDate


WITH this one below but that messing up the data grain :

SELECT
M.PatternDate patterndate,
ROUND(SUM(M.BlendedEventRevenueTotal),2) funcroomrev,
ROUND(SUM(M.FBRevenueTotal),2) fnbrev,
ROUND(SUM(M.AVRevTotal),2) avrev ,
ROUND(SUM(M.OtherRevTotal),2) otherrev ,
ROUND(SUM(M.BlendedEventRevenueTotal) / SUM(M.BlendedRoomnightsTotal),2) funcrevpergrprn,
ROUND(SUM(M.BlendedEventRevenueTotal) / SUM(M.BookedSqft),2) funcrevperbkdsqft,
ROUND(SUM(M.BlendedEventRevenueTotal) / 100,2) funcrevpersqft,
SUM(M.BlendedRoomnightsTotal) grprnleadvolume,
ROUND(SUM(CASE WHEN M.BookingStatus = ‘Definite’ THEN M.BlendedRoomnightsTotal ELSE 0 END) / SUM(M.BlendedRoomnightsTotal),3) conversion,
SUM(M.BlendedRoomnightsTotal) grprn,
ROUND(SUM(M.BlendedGuestroomRevenueTotal),2) grproomrev,
ROUND(SUM(M.BlendedGuestroomRevenueTotal) / SUM(M.BlendedRoomnightsTotal),0) grpadr
FROM(
SELECT mx.*
FROM group360all A
WHERE A.PatternDate BETWEEN ‘2018-01-01’ AND ‘2018-12-31’
AND A.BookingStatus IN [‘Definite’]
GROUP BY A.PatternDate, A.ExternalBookingId
LETTING mx = MAX([A.SnapshotDate, {A.BlendedEventRevenueTotal, A.FBRevenueTotal,A.AVRevTotal,A.OtherRevTotal,A.BlendedRoomnightsTotal,A.BlendedGuestroomRevenueTotal}])[1]
) M
GROUP BY M.PatternDate
ORDER BY M.PatternDate

CREATE INDEX majorindex ON group360all(PatternDate,ExternalBookingId,BookingStatus, SnapshotDate,ExternalMarketSegmentId,ExternalBookedById,RevenueType,BlendedEventRevenueTotal,FBRevenueTotal,AVRevTotal,OtherRevTotal,BlendedRoomnightsTotal,BookedSqft,BlendedGuestroomRevenueTotal)

SELECT
   M.PatternDate patterndate,
   ROUND(SUM(M.BlendedEventRevenueTotal),2) funcroomrev,
   ROUND(SUM(M.FBRevenueTotal),2) fnbrev,
   ROUND(SUM(M.AVRevTotal),2) avrev ,
   ROUND(SUM(M.OtherRevTotal),2) otherrev ,
   ROUND(SUM(M.BlendedEventRevenueTotal) / SUM(M.BlendedRoomnightsTotal),2) funcrevpergrprn,
   ROUND(SUM(M.BlendedEventRevenueTotal) / SUM(M.BookedSqft),2) funcrevperbkdsqft,
   ROUND(SUM(M.BlendedEventRevenueTotal) / 100,2) funcrevpersqft,
   SUM(M.BlendedRoomnightsTotal) grprnleadvolume,
   ROUND(SUM(CASE WHEN M.BookingStatus = "Definite" THEN M.BlendedRoomnightsTotal ELSE 0 END)/SUM(M.BlendedRoomnightsTotal),3) conversion,
   SUM(M.BlendedRoomnightsTotal) grprn,
   ROUND(SUM(M.BlendedGuestroomRevenueTotal),2) grproomrev,
   ROUND(SUM(M.BlendedGuestroomRevenueTotal) / SUM(M.BlendedRoomnightsTotal),0) grpadr
FROM ( SELECT mx.*
       FROM group360all  A
       WHERE A.PatternDate BETWEEN "2018-01-01" AND "2018-12-31"
       AND A.BookingStatus IN ["Definite"] AND A.ExternalBookingId IS NOT NULL
       GROUP BY A.PatternDate, A.ExternalBookingId
       LETTING mx = MAX([A.SnapshotDate, {A.PatternDate, A.BlendedEventRevenueTotal, A.FBRevenueTotal,
                                          A.AVRevTotal,A.OtherRevTotal,A.BlendedRoomnightsTotal, A.BlendedGuestroomRevenueTotal,
                                          A.BookedSqft, A.BookingStatus}])[1]
       ) M
GROUP BY M.PatternDate
ORDER BY M.PatternDate

I have adjusted index moved BookingStatus before SnapshotDate so that index can apply predicate during scan time. Also Added A.ExternalBookingId IS NOT NULL so that BookingStatus can be passed to indexer. You can see that in spans of the EXPLAIN.

How it works with MIN/MAX without JOIN you can read Select non-group by fields using sql query
MAX([arg1,arg2])[1]

arg2 is object and you must include all the fields you want in the parent query, otherwise those become MISSING and will not give right results.

1 Like

Wow ! I see how eben explained it in referred thread . New for us . Thanks and this perfectly worked .
Performance 400 ms … down from 2.5 secs .