mirror of https://github.com/citusdata/citus.git
fix NaN cost estimate on empty columnar tables (#4593)
Fixing a division by zero in the cost calculations for scanning a columnar table. Due to how the columns in a columnar table are counted an empty table would result in a division by zero. Instead this patch keeps the column selection ratio on zero when this happens, resulting in an accurate cost of zero pages to scan a columnar table. fixes #4589pull/4585/head
parent
07cf037b13
commit
07d3b4fd04
|
@ -242,7 +242,18 @@ ColumnarScanCost(RangeTblEntry *rte)
|
|||
{
|
||||
Bitmapset *attr_needed = rte->selectedCols;
|
||||
double numberOfColumnsRead = bms_num_members(attr_needed);
|
||||
double selectionRatio = numberOfColumnsRead / (double) maxColumnCount;
|
||||
double selectionRatio = 0;
|
||||
|
||||
/*
|
||||
* When no stripes are in the table we don't have a count in maxColumnCount. To
|
||||
* prevent a division by zero turning into a NaN we keep the ratio on zero.
|
||||
* This will result in a cost of 0 for scanning the table which is a reasonable
|
||||
* cost on an empty table.
|
||||
*/
|
||||
if (maxColumnCount != 0)
|
||||
{
|
||||
selectionRatio = numberOfColumnsRead / (double) maxColumnCount;
|
||||
}
|
||||
Cost scanCost = (double) totalStripeSize / BLCKSZ * selectionRatio;
|
||||
return scanCost;
|
||||
}
|
||||
|
|
|
@ -94,6 +94,19 @@ truncate t_compressed;
|
|||
-- alter type
|
||||
alter table t_uncompressed alter column a type text;
|
||||
alter table t_compressed alter column a type text;
|
||||
-- verify cost of scanning an empty table is zero, not NaN
|
||||
explain table t_uncompressed;
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------
|
||||
Custom Scan (ColumnarScan) on t_uncompressed (cost=0.00..0.00 rows=1 width=32)
|
||||
(1 row)
|
||||
|
||||
explain table t_compressed;
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------
|
||||
Custom Scan (ColumnarScan) on t_compressed (cost=0.00..0.00 rows=1 width=32)
|
||||
(1 row)
|
||||
|
||||
-- drop
|
||||
drop table t_compressed;
|
||||
drop table t_uncompressed;
|
||||
|
|
|
@ -43,6 +43,10 @@ truncate t_compressed;
|
|||
alter table t_uncompressed alter column a type text;
|
||||
alter table t_compressed alter column a type text;
|
||||
|
||||
-- verify cost of scanning an empty table is zero, not NaN
|
||||
explain table t_uncompressed;
|
||||
explain table t_compressed;
|
||||
|
||||
-- drop
|
||||
drop table t_compressed;
|
||||
drop table t_uncompressed;
|
||||
|
|
Loading…
Reference in New Issue