Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7c85aa3

Browse files
committed
Fix oversight in recent parameterized-path patch.
bitmap_scan_cost_est() has to be able to cope with a BitmapOrPath, butI'd taken a shortcut that didn't work for that case. Noted by Heikki.Add some regression tests since this area is evidently under-covered.
1 parentba3e415 commit7c85aa3

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

‎src/backend/optimizer/path/indxpath.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,28 +1317,31 @@ path_usage_comparator(const void *a, const void *b)
13171317

13181318
/*
13191319
* Estimate the cost of actually executing a bitmap scan with a single
1320-
* index path (no BitmapAnd, at least not at this level).
1320+
* index path (no BitmapAnd, at least not at this level; but it could be
1321+
* a BitmapOr).
13211322
*/
13221323
staticCost
13231324
bitmap_scan_cost_est(PlannerInfo*root,RelOptInfo*rel,Path*ipath)
13241325
{
13251326
BitmapHeapPathbpath;
1327+
Relidsrequired_outer;
13261328

1327-
/*Must be a simple IndexPath so that we can just copy its param_info */
1328-
Assert(IsA(ipath,IndexPath));
1329+
/*Identify required outer rels, in case it's a parameterized scan */
1330+
required_outer=get_bitmap_tree_required_outer(ipath);
13291331

13301332
/* Set up a dummy BitmapHeapPath */
13311333
bpath.path.type=T_BitmapHeapPath;
13321334
bpath.path.pathtype=T_BitmapHeapScan;
13331335
bpath.path.parent=rel;
1334-
bpath.path.param_info=ipath->param_info;
1336+
bpath.path.param_info=get_baserel_parampathinfo(root,rel,
1337+
required_outer);
13351338
bpath.path.pathkeys=NIL;
13361339
bpath.bitmapqual=ipath;
13371340

13381341
cost_bitmap_heap_scan(&bpath.path,root,rel,
13391342
bpath.path.param_info,
13401343
ipath,
1341-
get_loop_count(root,PATH_REQ_OUTER(ipath)));
1344+
get_loop_count(root,required_outer));
13421345

13431346
returnbpath.path.total_cost;
13441347
}

‎src/test/regress/expected/create_index.out

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,6 +2599,57 @@ RESET enable_seqscan;
25992599
RESET enable_indexscan;
26002600
RESET enable_bitmapscan;
26012601
DROP TABLE onek_with_null;
2602+
--
2603+
-- Check bitmap index path planning
2604+
--
2605+
EXPLAIN (COSTS OFF)
2606+
SELECT * FROM tenk1
2607+
WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
2608+
QUERY PLAN
2609+
-----------------------------------------------------------------------------------------------------------------------------------------
2610+
Bitmap Heap Scan on tenk1
2611+
Recheck Cond: (((thousand = 42) AND (tenthous = 1)) OR ((thousand = 42) AND (tenthous = 3)) OR ((thousand = 42) AND (tenthous = 42)))
2612+
-> BitmapOr
2613+
-> Bitmap Index Scan on tenk1_thous_tenthous
2614+
Index Cond: ((thousand = 42) AND (tenthous = 1))
2615+
-> Bitmap Index Scan on tenk1_thous_tenthous
2616+
Index Cond: ((thousand = 42) AND (tenthous = 3))
2617+
-> Bitmap Index Scan on tenk1_thous_tenthous
2618+
Index Cond: ((thousand = 42) AND (tenthous = 42))
2619+
(9 rows)
2620+
2621+
SELECT * FROM tenk1
2622+
WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
2623+
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
2624+
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
2625+
42 | 5530 | 0 | 2 | 2 | 2 | 42 | 42 | 42 | 42 | 42 | 84 | 85 | QBAAAA | SEIAAA | OOOOxx
2626+
(1 row)
2627+
2628+
EXPLAIN (COSTS OFF)
2629+
SELECT count(*) FROM tenk1
2630+
WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
2631+
QUERY PLAN
2632+
---------------------------------------------------------------------------------
2633+
Aggregate
2634+
-> Bitmap Heap Scan on tenk1
2635+
Recheck Cond: ((hundred = 42) AND ((thousand = 42) OR (thousand = 99)))
2636+
-> BitmapAnd
2637+
-> Bitmap Index Scan on tenk1_hundred
2638+
Index Cond: (hundred = 42)
2639+
-> BitmapOr
2640+
-> Bitmap Index Scan on tenk1_thous_tenthous
2641+
Index Cond: (thousand = 42)
2642+
-> Bitmap Index Scan on tenk1_thous_tenthous
2643+
Index Cond: (thousand = 99)
2644+
(11 rows)
2645+
2646+
SELECT count(*) FROM tenk1
2647+
WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
2648+
count
2649+
-------
2650+
10
2651+
(1 row)
2652+
26022653
--
26032654
-- Check behavior with duplicate index column contents
26042655
--

‎src/test/regress/sql/create_index.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,22 @@ RESET enable_bitmapscan;
858858

859859
DROPTABLE onek_with_null;
860860

861+
--
862+
-- Check bitmap index path planning
863+
--
864+
865+
EXPLAIN (COSTS OFF)
866+
SELECT*FROM tenk1
867+
WHERE thousand=42AND (tenthous=1OR tenthous=3OR tenthous=42);
868+
SELECT*FROM tenk1
869+
WHERE thousand=42AND (tenthous=1OR tenthous=3OR tenthous=42);
870+
871+
EXPLAIN (COSTS OFF)
872+
SELECTcount(*)FROM tenk1
873+
WHERE hundred=42AND (thousand=42OR thousand=99);
874+
SELECTcount(*)FROM tenk1
875+
WHERE hundred=42AND (thousand=42OR thousand=99);
876+
861877
--
862878
-- Check behavior with duplicate index column contents
863879
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp