From 38baddbc4197f87d14db70016a3bd6947bfaf523 Mon Sep 17 00:00:00 2001 From: Rock Date: Tue, 11 Jun 2024 17:27:02 +0800 Subject: [PATCH] Fix the sorting error issue for the set type. Conflicts: src/test/regress/expected/mysql_syntax.out src/test/regress/sql/mysql_syntax.sql --- src/gausskernel/optimizer/plan/initsplan.cpp | 18 ++++++++++++- src/test/regress/expected/hw_datatype_set.out | 10 +++---- src/test/regress/expected/mysql_syntax.out | 26 +++++++++++++++++++ src/test/regress/sql/hw_datatype_set.sql | 4 +-- src/test/regress/sql/mysql_syntax.sql | 11 ++++++++ 5 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/gausskernel/optimizer/plan/initsplan.cpp b/src/gausskernel/optimizer/plan/initsplan.cpp index 8ce63ff77..d99fd5b8d 100644 --- a/src/gausskernel/optimizer/plan/initsplan.cpp +++ b/src/gausskernel/optimizer/plan/initsplan.cpp @@ -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); diff --git a/src/test/regress/expected/hw_datatype_set.out b/src/test/regress/expected/hw_datatype_set.out index 556ad6000..ef43f477d 100644 --- a/src/test/regress/expected/hw_datatype_set.out +++ b/src/test/regress/expected/hw_datatype_set.out @@ -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; \ No newline at end of file +drop table test_check1; diff --git a/src/test/regress/expected/mysql_syntax.out b/src/test/regress/expected/mysql_syntax.out index d9d7d5bb6..11c5f9170 100644 --- a/src/test/regress/expected/mysql_syntax.out +++ b/src/test/regress/expected/mysql_syntax.out @@ -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 diff --git a/src/test/regress/sql/hw_datatype_set.sql b/src/test/regress/sql/hw_datatype_set.sql index fd4bebb5e..a8848346b 100644 --- a/src/test/regress/sql/hw_datatype_set.sql +++ b/src/test/regress/sql/hw_datatype_set.sql @@ -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; \ No newline at end of file +drop table test_check1; diff --git a/src/test/regress/sql/mysql_syntax.sql b/src/test/regress/sql/mysql_syntax.sql index 0bf175198..bdf12f1d9 100644 --- a/src/test/regress/sql/mysql_syntax.sql +++ b/src/test/regress/sql/mysql_syntax.sql @@ -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;