Skip to content

Commit

Permalink
Fix non-default collation fallbacks
Browse files Browse the repository at this point in the history
For type NAMEOID, the default collation is C. Make sure various nodetypes are
aware of it.  Earlier only VAR node type took care of it. Extend it CONST and
OPEXPR.

A note about test case change in `select` ICG test. The test cases are supposed
to test for index scan on partial indexes. Earlier ORCA would fall back to
planner. After this fix, ORCA started to give sequential scan which was flaky
with explain analyze. So just like planner, we have turned off tablescan for
these tests. They are falling back to Planner for now.
  • Loading branch information
pobbatihari authored and my-ship-it committed Nov 1, 2024
1 parent e53b57c commit 1cdccbe
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 100 deletions.
8 changes: 0 additions & 8 deletions contrib/auto_explain/expected/auto_explain_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ SET auto_explain.log_timing = FALSE;
LOG: statement: SET auto_explain.log_timing = FALSE;
SET auto_explain.log_verbose = FALSE;
LOG: statement: SET auto_explain.log_verbose = FALSE;
-- start_ignore
-- GPDB_12_MERGE_FIXME: Non default collations
-- end_ignore
SELECT relname FROM pg_class WHERE relname='pg_class';
LOG: statement: SELECT relname FROM pg_class WHERE relname='pg_class';
"Feature not supported: Non-default collation",
LOG: duration: 0.026 ms plan:
Query Text: SELECT relname FROM pg_class WHERE relname='pg_class';
Index Only Scan using pg_class_relname_nsp_index on pg_class (cost=0.15..4.17 rows=1 width=64) (actual rows=1 loops=1)
Expand Down Expand Up @@ -77,12 +73,8 @@ LOG: statement: SET auto_explain.log_triggers = FALSE;
SET auto_explain.log_verbose = TRUE;
LOG: statement: SET auto_explain.log_verbose = TRUE;
-- this select should not dump execution plan
-- start_ignore
-- GPDB_12_MERGE_FIXME: Non default collation
-- end_ignore
SELECT relname FROM pg_class WHERE relname='pg_class';
LOG: statement: SELECT relname FROM pg_class WHERE relname='pg_class';
"Feature not supported: Non-default collation",
relname
----------
pg_class
Expand Down
114 changes: 114 additions & 0 deletions contrib/btree_gin/expected/name_optimizer.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
set enable_seqscan=off;
CREATE TABLE test_name (
i name
);
INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
CREATE INDEX idx_name ON test_name USING gin (i);
SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
i
-----
a
ab
abb
(3 rows)

SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
i
-----
a
ab
abb
abc
(4 rows)

SELECT * FROM test_name WHERE i='abc' ORDER BY i;
i
-----
abc
(1 row)

SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
i
-----
abc
axy
xyz
(3 rows)

SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
i
-----
axy
xyz
(2 rows)

EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
QUERY PLAN
---------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
Merge Key: i
-> Sort
Sort Key: i
-> Bitmap Heap Scan on test_name
Recheck Cond: (i < 'abc'::name)
-> Bitmap Index Scan on idx_name
Index Cond: (i < 'abc'::name)
Optimizer: Postgres query optimizer
(9 rows)

EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
QUERY PLAN
----------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
Merge Key: i
-> Sort
Sort Key: i
-> Bitmap Heap Scan on test_name
Recheck Cond: (i <= 'abc'::name)
-> Bitmap Index Scan on idx_name
Index Cond: (i <= 'abc'::name)
Optimizer: Postgres query optimizer
(9 rows)

EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
QUERY PLAN
---------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
Merge Key: i
-> Sort
Sort Key: i
-> Bitmap Heap Scan on test_name
Recheck Cond: (i = 'abc'::name)
-> Bitmap Index Scan on idx_name
Index Cond: (i = 'abc'::name)
Optimizer: Pivotal Optimizer (GPORCA)
(9 rows)

EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
QUERY PLAN
----------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
Merge Key: i
-> Sort
Sort Key: i
-> Bitmap Heap Scan on test_name
Recheck Cond: (i >= 'abc'::name)
-> Bitmap Index Scan on idx_name
Index Cond: (i >= 'abc'::name)
Optimizer: Postgres query optimizer
(9 rows)

EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
QUERY PLAN
---------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
Merge Key: i
-> Sort
Sort Key: i
-> Bitmap Heap Scan on test_name
Recheck Cond: (i > 'abc'::name)
-> Bitmap Index Scan on idx_name
Index Cond: (i > 'abc'::name)
Optimizer: Postgres query optimizer
(9 rows)

8 changes: 4 additions & 4 deletions src/backend/optimizer/util/walkers.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,11 @@ check_collation_walker(Node *node, check_collation_context *context)
switch (nodeTag(node))
{
case T_Var:
type = (castNode(Var, node))->vartype;
case T_Const:
case T_OpExpr:
type = exprType((node));
collation = exprCollation(node);
if (type == NAMEOID)
if (type == NAMEOID || type == NAMEARRAYOID)
{
if (collation != C_COLLATION_OID)
context->foundNonDefaultCollation = 1;
Expand All @@ -922,8 +924,6 @@ check_collation_walker(Node *node, check_collation_context *context)
context->foundNonDefaultCollation = 1;
}
break;
case T_Const:
case T_OpExpr:
case T_ScalarArrayOpExpr:
case T_DistinctExpr:
case T_BoolExpr:
Expand Down
6 changes: 3 additions & 3 deletions src/test/regress/expected/aggregates_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ SET optimizer_trace_fallback to on;
-- end_ignore
select * from aggordview1 order by ten;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
DETAIL: Feature not supported: Aggregate functions with FILTER
ten | p50 | px | rank
-----+-----+-----+------
0 | 490 | | 101
Expand Down Expand Up @@ -2676,7 +2676,7 @@ SET optimizer_trace_fallback to on;
-- end_ignore
select * from aggordview1 order by ten;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
DETAIL: Feature not supported: Aggregate functions with FILTER
ten | p50 | px | rank
-----+-----+-----+------
0 | 490 | | 101
Expand Down Expand Up @@ -3502,7 +3502,7 @@ drop table agg_hash_4;
set enable_indexonlyscan = off;
explain analyze select count(*) from pg_class, (select count(*) >0 from (select count(*) from pg_class where relname like 't%')x)y;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
DETAIL: Feature not supported: Queries on master-only tables
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------
Aggregate (cost=10000000017.74..10000000017.75 rows=1 width=8) (actual time=0.142..0.142 rows=1 loops=1)
Expand Down
2 changes: 1 addition & 1 deletion src/test/regress/expected/autostats.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- s/tableoid \d+/tableoid XXXXX/
-- end_matchsubs
-- start_matchignore
-- m/^LOG: .*Feature not supported: Non-default collation./
-- m/^LOG: .*Feature not supported: Queries on master-only tables./
-- m/^LOG:.*ERROR,"PG exception raised"/
-- end_matchignore
set gp_autostats_mode=on_change;
Expand Down
20 changes: 10 additions & 10 deletions src/test/regress/expected/bfv_index_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ explain select * from bfv_tab1, (values(147, 'RFAAAA'), (931, 'VJAAAA')) as v (i
WHERE bfv_tab1.unique1 = v.i and bfv_tab1.stringu1 = v.j;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.06..279.08 rows=14 width=280)
-> Hash Join (cost=0.06..278.81 rows=5 width=280)
Gather Motion 3:1 (slice1; segments: 3) (cost=0.06..93.80 rows=14 width=280)
-> Hash Join (cost=0.06..93.62 rows=5 width=280)
Hash Cond: ((bfv_tab1.unique1 = "*VALUES*".column1) AND (bfv_tab1.stringu1 = ("*VALUES*".column2)::text))
-> Seq Scan on bfv_tab1 (cost=0.00..219.00 rows=3967 width=244)
-> Hash (cost=0.03..0.03 rows=1 width=36)
-> Values Scan on "*VALUES*" (cost=0.00..0.03 rows=1 width=36)
-> Seq Scan on bfv_tab1 (cost=0.00..73.67 rows=3967 width=244)
-> Hash (cost=0.03..0.03 rows=2 width=36)
-> Values Scan on "*VALUES*" (cost=0.00..0.03 rows=2 width=36)
Optimizer: Postgres query optimizer
(7 rows)

Expand All @@ -40,12 +40,12 @@ explain select * from bfv_tab1, (values(147, 'RFAAAA'), (931, 'VJAAAA')) as v (i
WHERE bfv_tab1.unique1 = v.i and bfv_tab1.stringu1 = v.j;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.01..0.15 rows=4 width=280)
-> Hash Join (cost=0.01..0.09 rows=2 width=280)
Gather Motion 3:1 (slice1; segments: 3) (cost=0.03..0.12 rows=3 width=280)
-> Hash Join (cost=0.03..0.08 rows=1 width=280)
Hash Cond: (("*VALUES*".column1 = bfv_tab1.unique1) AND (("*VALUES*".column2)::text = bfv_tab1.stringu1))
-> Values Scan on "*VALUES*" (cost=0.00..0.03 rows=1 width=36)
-> Hash (cost=0.00..0.00 rows=1 width=244)
-> Seq Scan on bfv_tab1 (cost=0.00..0.00 rows=1 width=244)
-> Values Scan on "*VALUES*" (cost=0.00..0.03 rows=2 width=36)
-> Hash (cost=0.01..0.01 rows=1 width=244)
-> Seq Scan on bfv_tab1 (cost=0.00..0.01 rows=1 width=244)
Optimizer: Postgres query optimizer
(7 rows)

Expand Down
5 changes: 0 additions & 5 deletions src/test/regress/expected/brin_ao_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,6 @@ WARNING: ORCA did not produce a bitmap indexscan plan for (inetcol,>,inet,0.0.0
WARNING: ORCA did not produce a bitmap indexscan plan for (inetcol,>=,inet,0.0.0.0,125)
WARNING: ORCA did not produce a bitmap indexscan plan for (lsncol,IS,pg_lsn,,25)
WARNING: ORCA did not produce a bitmap indexscan plan for (lsncol,"IS NOT",pg_lsn,,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,<,name,ZZAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,<=,name,ZZAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,=,name,MAAAAA,2)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,>,name,AAAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,>=,name,AAAAAA,100)
-- Note: ORCA does not support all of the above operators:
-- - standard comparison operators on inet and cidr columns
-- because ORCA does not look at the second occurrence of a column in an index,
Expand Down
5 changes: 0 additions & 5 deletions src/test/regress/expected/brin_aocs_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,6 @@ WARNING: ORCA did not produce a bitmap indexscan plan for (inetcol,>,inet,0.0.0
WARNING: ORCA did not produce a bitmap indexscan plan for (inetcol,>=,inet,0.0.0.0,125)
WARNING: ORCA did not produce a bitmap indexscan plan for (lsncol,IS,pg_lsn,,25)
WARNING: ORCA did not produce a bitmap indexscan plan for (lsncol,"IS NOT",pg_lsn,,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,<,name,ZZAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,<=,name,ZZAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,=,name,MAAAAA,2)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,>,name,AAAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,>=,name,AAAAAA,100)
-- Note: ORCA does not support all of the above operators:
-- - standard comparison operators on inet and cidr columns
-- because ORCA does not look at the second occurrence of a column in an index,
Expand Down
5 changes: 0 additions & 5 deletions src/test/regress/expected/brin_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,6 @@ WARNING: ORCA did not produce a bitmap indexscan plan for (inetcol,>,inet,0.0.0
WARNING: ORCA did not produce a bitmap indexscan plan for (inetcol,>=,inet,0.0.0.0,125)
WARNING: ORCA did not produce a bitmap indexscan plan for (lsncol,IS,pg_lsn,,25)
WARNING: ORCA did not produce a bitmap indexscan plan for (lsncol,"IS NOT",pg_lsn,,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,<,name,ZZAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,<=,name,ZZAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,=,name,MAAAAA,2)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,>,name,AAAAAA,100)
WARNING: ORCA did not produce a bitmap indexscan plan for (namecol,>=,name,AAAAAA,100)
-- Note: ORCA does not support all of the above operators:
-- - standard comparison operators on inet and cidr columns
-- because ORCA does not look at the second occurrence of a column in an index,
Expand Down
4 changes: 0 additions & 4 deletions src/test/regress/expected/gp_array_agg_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,10 @@ INSERT INTO arrtest (a, b[1:2][1:2][1:2], c, d, e, f, g)
VALUES ('{1,2}', '{{{0,0},{1,2}},{{3,4},{5,6}}}', '{"foo"}',
'{{"elt1", "elt2"}}', '{1.1, 2.2}',
'{"abc","abcde"}', '{"abc","abcde"}');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
INSERT INTO arrtest (a, b[1:2][1:2][1:2], c, d, e, f, g)
VALUES ('{1,2}', '{{{7,8},{9,10}},{{11,12},{13,14}}}', '{"bar"}',
'{{"elt1", "elt2"}}', '{"3.3", "4.4"}',
'{"abc","abcde"}', '{"abc","abcde"}');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
SELECT $query$
select
array_agg(a) agg_a,
Expand Down
20 changes: 2 additions & 18 deletions src/test/regress/expected/gporca_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -8134,35 +8134,21 @@ string4 name
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'unique1' as the Cloudberry Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into orca.onek values (931,1,1,3,1,11,1,31,131,431,931,2,3,'VJAAAA','BAAAAA','HHHHxx');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
insert into orca.onek values (714,2,0,2,4,14,4,14,114,214,714,8,9,'MBAAAA','CAAAAA','OOOOxx');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
insert into orca.onek values (711,3,1,3,1,11,1,11,111,211,711,2,3,'JBAAAA','DAAAAA','VVVVxx');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
insert into orca.onek values (883,4,1,3,3,3,3,83,83,383,883,6,7,'ZHAAAA','EAAAAA','AAAAxx');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
insert into orca.onek values (439,5,1,3,9,19,9,39,39,439,439,18,19,'XQAAAA','FAAAAA','HHHHxx');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
insert into orca.onek values (670,6,0,2,0,10,0,70,70,170,670,0,1,'UZAAAA','GAAAAA','OOOOxx');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
insert into orca.onek values (543,7,1,3,3,3,3,43,143,43,543,6,7,'XUAAAA','HAAAAA','VVVVxx');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
select ten, sum(distinct four) from orca.onek a
group by ten
having exists (select 1 from orca.onek b where sum(distinct a.four) = b.four);
ten | sum
-----+-----
0 | 2
4 | 2
1 | 3
3 | 3
4 | 2
9 | 3
(5 rows)

Expand Down Expand Up @@ -9227,7 +9213,7 @@ WITH (appendonly=true, compresstype=zlib) DISTRIBUTED BY (uid136);
SET
relpages = 30915::int, reltuples = 7.28661e+07::real WHERE relname = 'tmp_verd_s_pp_provtabs_agt_0015_extract1' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'xvclin');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
DETAIL: Operator Fallback: InnerIndexNestLoopJoin may have wrong plan not supported
insert into pg_statistic
values (
'orca.tmp_verd_s_pp_provtabs_agt_0015_extract1'::regclass,
Expand Down Expand Up @@ -9748,8 +9734,6 @@ create table orca.arrtest (
) DISTRIBUTED RANDOMLY;
insert into orca.arrtest (a[1:5], b[1:1][1:2][1:2], c, d)
values ('{1,2,3,4,5}', '{{{0,0},{1,2}}}', '{}', '{}');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
select a[1:3], b[1][2][1], c[1], d[1][1] FROM orca.arrtest order by 1,2,3,4;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Non-default collation
Expand Down
Loading

0 comments on commit 1cdccbe

Please sign in to comment.