mirror of
https://github.com/postgres/postgres.git
synced 2026-01-05 23:38:41 +03:00
Teach bitmap path generation about transforming OR-clauses to SAOP's
When optimizer generates bitmap paths, it considers breaking OR-clause arguments one-by-one. But now, a group of similar OR-clauses can be transformed into SAOP during index matching. So, bitmap paths should keep up. This commit teaches bitmap paths generation machinery to group similar OR-clauses into dedicated RestrictInfos. Those RestrictInfos are considered both to match index as a whole (as SAOP), or to match as a set of individual OR-clause argument one-by-one (the old way). Therefore, bitmap path generation will takes advantage of OR-clauses to SAOP's transformation. The old way of handling them is also considered. So, there shouldn't be planning regression. Discussion: https://postgr.es/m/CAPpHfdu5iQOjF93vGbjidsQkhHvY2NSm29duENYH_cbhC6x%2BMg%40mail.gmail.com Author: Alexander Korotkov, Andrey Lepikhov Reviewed-by: Alena Rybakina, Andrei Lepikhov, Jian he, Robert Haas Reviewed-by: Peter Geoghegan
This commit is contained in:
@@ -738,6 +738,23 @@ SELECT * FROM tenk1
|
||||
SELECT * FROM tenk1
|
||||
WHERE thousand = 42 AND (tenthous = 1 OR tenthous = (SELECT 1 + 2) OR tenthous = 42);
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM tenk1
|
||||
WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous IS NULL);
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM tenk1
|
||||
WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous = 42::int8);
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM tenk1
|
||||
WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous::int2 = 3::int8 OR tenthous::int2 = 42::int8);
|
||||
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM tenk1
|
||||
WHERE thousand = 42 AND (tenthous = 1::int2 OR tenthous = 3::int8 OR tenthous = 42::int8);
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM tenk1
|
||||
WHERE hundred = 42 AND (thousand = 42 OR thousand = 99);
|
||||
@@ -1321,6 +1338,27 @@ SELECT b.relname,
|
||||
ORDER BY 1;
|
||||
DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before;
|
||||
|
||||
-- Check bitmap scan can consider similar OR arguments separately without
|
||||
-- grouping them into SAOP.
|
||||
CREATE TABLE bitmap_split_or (a int NOT NULL, b int NOT NULL, c int NOT NULL);
|
||||
INSERT INTO bitmap_split_or (SELECT 1, 1, i FROM generate_series(1, 1000) i);
|
||||
INSERT INTO bitmap_split_or (select i, 2, 2 FROM generate_series(1, 1000) i);
|
||||
VACUUM ANALYZE bitmap_split_or;
|
||||
CREATE INDEX t_b_partial_1_idx ON bitmap_split_or (b) WHERE a = 1;
|
||||
CREATE INDEX t_b_partial_2_idx ON bitmap_split_or (b) WHERE a = 2;
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM bitmap_split_or WHERE (a = 1 OR a = 2) AND b = 2;
|
||||
DROP INDEX t_b_partial_1_idx;
|
||||
DROP INDEX t_b_partial_2_idx;
|
||||
CREATE INDEX t_a_b_idx ON bitmap_split_or (a, b);
|
||||
CREATE INDEX t_b_c_idx ON bitmap_split_or (b, c);
|
||||
CREATE STATISTICS t_a_b_stat (mcv) ON a, b FROM bitmap_split_or;
|
||||
CREATE STATISTICS t_b_c_stat (mcv) ON b, c FROM bitmap_split_or;
|
||||
ANALYZE bitmap_split_or;
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM bitmap_split_or WHERE a = 1 AND (b = 1 OR b = 2) AND c = 2;
|
||||
DROP TABLE bitmap_split_or;
|
||||
|
||||
--
|
||||
-- REINDEX SCHEMA
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user