Fix the sorting error issue for the set type.

Conflicts:
	src/test/regress/expected/mysql_syntax.out
	src/test/regress/sql/mysql_syntax.sql
This commit is contained in:
Rock
2024-06-11 17:27:02 +08:00
committed by yaoxin
parent b776555275
commit 38baddbc41
5 changed files with 61 additions and 8 deletions

View File

@ -2105,7 +2105,7 @@ static void check_mergejoinable(RestrictInfo* restrictinfo)
Expr* clause = restrictinfo->clause;
Oid opno;
Node* leftarg = NULL;
Node* rightarg = NULL;
if (restrictinfo->pseudoconstant)
return;
if (!is_opclause(clause))
@ -2115,6 +2115,22 @@ static void check_mergejoinable(RestrictInfo* restrictinfo)
opno = ((OpExpr*)clause)->opno;
leftarg = (Node*)linitial(((OpExpr*)clause)->args);
rightarg = (Node*)lsecond(((OpExpr*)clause)->args);
/*
* For data of type set, using the merge join plan will result in inconsistent outcomes.
*/
if (nodeTag(leftarg) == T_Var) {
Var* leftCol = (Var*)leftarg;
if (type_is_set(leftCol->vartype)) {
return;
}
}
if (nodeTag(rightarg) == T_Var) {
Var* rightCol = (Var*)rightarg;
if (type_is_set(rightCol->vartype)) {
return;
}
}
if (op_mergejoinable(opno, exprType(leftarg)) && !contain_volatile_functions((Node*)clause))
restrictinfo->mergeopfamilies = get_mergejoin_opfamilies(opno);

View File

@ -4428,13 +4428,13 @@ select
from
test_collation2 as t2,
test_collation2 as t3
where t2.a = t3.a;
where t2.a = t3.a order by 1;
a | a
--------+--------
aaa | aaa
高斯ss | 高斯ss
高斯SS | 高斯SS
AAA | AAA
aaa | aaa
高斯SS | 高斯SS
高斯ss | 高斯ss
(4 rows)
-- '<>'
@ -5344,4 +5344,4 @@ DETAIL: N/A
insert into test_check1 values('B ');
insert into test_check1 values('C');
insert into test_check1 values('c');
drop table test_check1;
drop table test_check1;

View File

@ -526,6 +526,32 @@ NOTICE: SQLSTATE = 22012, SQLERRM = division by zero
(1 row)
drop table if exists test1;
NOTICE: table "test1" does not exist, skipping
drop table if exists test2;
NOTICE: table "test2" does not exist, skipping
create table test1 (c set('a','b','c','d'));
NOTICE: CREATE TABLE will create implicit set "test1_c_set" for column "test1.c"
insert into test1 values ('a'),('b'),('c'),('d');
create table test2 (c set('d','c','b','a'));
NOTICE: CREATE TABLE will create implicit set "test2_c_set" for column "test2.c"
insert into test2 values ('a'),('b'),('c'),('d');
set enable_nestloop=off;
set enable_hashjoin=off;
explain (costs off) select test1.c from test1, test2 where test1.c = test2.c order by 1;
QUERY PLAN
------------------------------------------
Sort
Sort Key: test1.c
-> Nested Loop
Join Filter: (test1.c = test2.c)
-> Seq Scan on test1
-> Materialize
-> Seq Scan on test2
(7 rows)
set enable_nestloop=on;
set enable_hashjoin=on;
\c regression
drop trigger animal_trigger1;
ERROR: drop trigger without table name only support in B-format database

View File

@ -879,7 +879,7 @@ select
from
test_collation2 as t2,
test_collation2 as t3
where t2.a = t3.a;
where t2.a = t3.a order by 1;
-- '<>'
select a, b from test_collation_op where a <> b; -- set <> other set
@ -1118,4 +1118,4 @@ insert into test_check1 values('a');
insert into test_check1 values('B ');
insert into test_check1 values('C');
insert into test_check1 values('c');
drop table test_check1;
drop table test_check1;

View File

@ -411,6 +411,17 @@ exception
END;
/
call test_condition_7();
drop table if exists test1;
drop table if exists test2;
create table test1 (c set('a','b','c','d'));
insert into test1 values ('a'),('b'),('c'),('d');
create table test2 (c set('d','c','b','a'));
insert into test2 values ('a'),('b'),('c'),('d');
set enable_nestloop=off;
set enable_hashjoin=off;
explain (costs off) select test1.c from test1, test2 where test1.c = test2.c order by 1;
set enable_nestloop=on;
set enable_hashjoin=on;
\c regression
drop trigger animal_trigger1;
drop trigger if exists animal_trigger1;