hey team, I am getting different query plans for t...
# troubleshooting
y
hey team, I am getting different query plans for the same query. The table has range index over 2 columns
timestamp
and
pid
. When I run
Copy code
explain plan for
select cid, pid, count(cid) as volume
from test_table
where UTCTimestamp > ago('PT30M') and pid < 150 and pid > 100
group by cid, pid
having count(cid) > 10
order by volume desc
sometimes it uses range-index,
Copy code
FILTER_RANGE_INDEX(indexLookUp:range_index,operator:RANGE,predicate:UTCTimestamp > '1740503053957')
FILTER_RANGE_INDEX(indexLookUp:range_index,operator:RANGE,predicate:(pid > '41000' AND pid < '41050'))
sometimes it adds full scan to the plan
Copy code
FILTER_FULL_SCAN(operator:RANGE,predicate:UTCTimestamp > '1740502920093')
FILTER_FULL_SCAN(operator:RANGE,predicate:(pid > '100' AND pid < '150'))
what can be a possible cause for the same input but different output from broker ?
b
Hi. Pinot adjusts query plans based on actual segment metadata and statistics (e.g. min/max values). If , during query compilation, pinot finds that: • given predicate will be satisfied by all rows in a given segment, it might remove them from segment's plan • given predicate will not be satisfied by any row in segment, it won't process it at all Please have a look at https://docs.pinot.apache.org/users/user-guide-query/query-syntax/explain-plan and try using verbose mode.
y
do you know any user-friendly way of reading the query plans ? for better visualization
y
Is this table a realtime table with consuming segments? I believe the range index doesn't have a realtime / mutable version and is only created for committed segments.
So if your explain plan is run against a consuming segment, it wouldn't be able to make use of a range index. Like Bolek suggested above, the best way to confirm that would be to use the verbose mode for the explain plan.
y
this is what I got from verbose query plan and it looks little odd. It shows different operators for same operator id in different steps.
Copy code
{
  "columns": [
    "Operator",
    "Operator_Id",
    "Parent_Id"
  ],
  "records": [
    [
      "BROKER_REDUCE(havingFilter:count(cid) > '1000',sort:[count(cid) DESC],limit:1000)",
      1,
      0
    ],
    [
      "COMBINE_GROUP_BY",
      2,
      1
    ],
    [
      "PLAN_START(numSegmentsForThisPlan:24)",
      -1,
      -1
    ],
    [
      "GROUP_BY(groupKeys:cid, pid, aggregations:count(*))",
      3,
      2
    ],
    [
      "PROJECT(templateInstanceVersion, templateInstanceId, pid, cid)",
      4,
      3
    ],
    [
      "DOC_ID_SET",
      5,
      4
    ],
    [
      "FILTER_AND",
      6,
      5
    ],
    [
      "FILTER_FULL_SCAN(operator:RANGE,predicate:(pid > '41000' AND pid < '41050'))",
      7,
      6
    ],
    [
      "FILTER_FULL_SCAN(operator:RANGE,predicate:UTCTimestamp > '1740506493999')",
      8,
      6
    ],
    [
      "PLAN_START(numSegmentsForThisPlan:2545)",
      -1,
      -1
    ],
    [
      "GROUP_BY(groupKeys:cid, pid, aggregations:count(*))",
      3,
      2
    ],
    [
      "PROJECT(templateInstanceVersion, templateInstanceId, pid, cid)",
      4,
      3
    ],
    [
      "DOC_ID_SET",
      5,
      4
    ],
    [
      "FILTER_AND",
      6,
      5
    ],
    [
      "FILTER_RANGE_INDEX(indexLookUp:range_index,operator:RANGE,predicate:(pid > '41000' AND pid < '41050'))",
      7,
      6
    ],
    [
      "FILTER_RANGE_INDEX(indexLookUp:range_index,operator:RANGE,predicate:UTCTimestamp > '1740506493999')",
      8,
      6
    ]
  ]
}
If you track operator number 7 and 8, it is marked as both full scan and range index.
oh, is it running full scan on consuming segments and using range index on comitted segments ?
y
oh, is it running full scan on consuming segments and using range index on comitted segments ?
Yeah, that's my theory
PLAN_START(numSegmentsForThisPlan:24)
PLAN_START(numSegmentsForThisPlan:2545)
Do you have 24 consuming segments in that table and 2545 committed segments? If yes, that would confirm the theory.
y
24 consuming, yes but more than 2545. 2545 can be the matching segments ?
y
Ah right, that would make sense
• given predicate will be satisfied by all rows in a given segment, it might remove them from segment's plan
In this case, we would've seen
FILTER_MATCH_ENTIRE_SEGMENT
in the plan I believe.
y
Indeed, when I remove the whole where clause, I see it in the plan
Copy code
FILTER_MATCH_ENTIRE_SEGMENT(docs:2911586)