Zoltán Borók-Nagy created IMPALA-15852:
------------------------------------------
Summary: COMPUTE_PROCESSING_COST costs a TopN by log2 of its input
instead of its heap size
Key: IMPALA-15852
URL: https://issues.apache.org/jira/browse/IMPALA-15852
Project: IMPALA
Issue Type: Bug
Components: Frontend
Reporter: Zoltán Borók-Nagy
SortNode.computeProcessingCost() costs a TOPN or PARTITIONED_TOPN node as
COST_COEFFICIENT_SORT_TOPN * N * log2 N for N input rows, with
COST_COEFFICIENT_SORT_TOPN = 0.5638. The limit does not enter the cost. The
backend keeps at most TopNPlanNode::heap_capacity() rows per heap, which is
limit + offset, or the per-partition limit + offset for a partitioned TopN.
Once a heap is full, TopNNode::Heap::InsertTupleRow() compares each row with
the top of the heap, and only a row that enters the heap pays HeapifyFromTop()
over log2 of the heap size. When the TopN's costing segment is the most
expensive one of its fragment, this overcharge sets the parallelism of the
fragment.
Example on master, TpcdsCpuCostPlannerTest (TPC-DS 3TB stats, 10 executors,
MAX_FRAGMENT_INSTANCES_PER_NODE=12): in q3 the TOP-N with LIMIT 100 reads 9.00M
rows and costs 117158429, log2 9.00M = 23.1 per row against 6.6 for a heap of
100. Its segment gives fragment F03 max-parallelism=20, so F03 runs 20
instances; the aggregation segment alone would give 10. In q4 the TOP-N over
591.78M join rows costs 9.72G of the 10.23G first segment of F12. That raises
max-parallelism to 1030, so F12 and its five partitioned join build fragments
run at the cap of 120 instances; without the TopN the segment would give 60.
Fix: cost a TopN as N * (1 + log2 H), where H is the smaller of N and the heap
capacity, and refit COST_COEFFICIENT_SORT_TOPN against TopN timings in query
profiles. A partitioned TopN should also pay log2 of its in-memory partitions
per row for the heap lookup, and a sort of the rows it passes to its Sorter. A
fragment that is a single scan under a TopN with limit + offset up to 1000
sends few rows per instance, so it should keep the bound of
ScanNode.computeMaxScannerThreadsForCPC() rather than lose instances with the
lower cost.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)