From 80263d9aa741013e8c0e6ef216b3a5501d9a88c6 Mon Sep 17 00:00:00 2001 From: laishenghao Date: Wed, 17 Jul 2024 11:46:00 +0800 Subject: [PATCH] =?UTF-8?q?concat=E3=80=81concat=5Fws=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=94=AF=E6=8C=81simplify=EF=BC=9B=E5=AD=97=E6=AE=B5=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/parser/parse_expr.cpp | 27 +- src/gausskernel/optimizer/util/clauses.cpp | 54 +- .../expected/stable_function_shippable.out | 468 ++++++++++++++++++ .../regress/input/insert_right_ref.source | 2 +- .../regress/output/insert_right_ref.source | 12 +- .../regress/sql/stable_function_shippable.sql | 77 +++ 6 files changed, 630 insertions(+), 10 deletions(-) diff --git a/src/common/backend/parser/parse_expr.cpp b/src/common/backend/parser/parse_expr.cpp index 7a55479be..85384adae 100644 --- a/src/common/backend/parser/parse_expr.cpp +++ b/src/common/backend/parser/parse_expr.cpp @@ -232,6 +232,31 @@ static Const* BuildColumnBaseValue(Form_pg_attribute attTup) return nullptr; } +static bool IsConstDefaultValue(FuncExpr* expr) +{ + if (expr->funcformat != COERCE_IMPLICIT_CAST) { + return false; + } + + ListCell* cell = NULL; + List* args = expr->args; + bool isFirstArg = true; + + foreach (cell, args) { + Node* arg = (Node*)lfirst(cell); + if (isFirstArg) { + isFirstArg = false; + if (!IsA(arg, Const) && + !(IsA(arg, FuncExpr) && ((FuncExpr*)arg)->funcformat == COERCE_IMPLICIT_CAST)) { + return false; + } + } else if (!IsA(arg, Const)) { + return false; + } + } + return true; +} + static void AddDefaultExprNode(ParseState* pstate) { RightRefState* refState = pstate->rightRefState; @@ -265,7 +290,7 @@ static void AddDefaultExprNode(ParseState* pstate) refState->constValues[i] = nullptr; } else if (IsA(node, Const)) { refState->constValues[i] = (Const*)node; - } else if (IsA(node, FuncExpr)) { + } else if (IsA(node, FuncExpr) && IsConstDefaultValue((FuncExpr*)node)) { FuncExpr* expr = (FuncExpr*)node; List* args = expr->args; Expr* simple = simplify_function(expr->funcid, expr->funcresulttype, exprTypmod((const Node*)expr), diff --git a/src/gausskernel/optimizer/util/clauses.cpp b/src/gausskernel/optimizer/util/clauses.cpp index 642ed7753..b447c3ecf 100644 --- a/src/gausskernel/optimizer/util/clauses.cpp +++ b/src/gausskernel/optimizer/util/clauses.cpp @@ -4197,7 +4197,7 @@ static Oid pre_evaluate_func[] = {CURRENTSCHEMAFUNCOID, CURRENTDATABASEFUNCOID, PGCLIENTENCODINGFUNCOID}; -static bool is_safe_simplify_func(Oid funcid) +static bool is_safe_simplify_func(Oid funcid, List *args) { if (funcid == InvalidOid) { return false; @@ -4207,6 +4207,56 @@ static bool is_safe_simplify_func(Oid funcid) return true; } } + + /* handle some special func */ + if (funcid == CONCATFUNCOID || funcid == CONCATWSFUNCOID) { + ListCell* arg = NULL; + foreach (arg, args) { + Oid typ = exprType((Node*)lfirst(arg)); + /* + * binary: not ok, bytea_output will affect the result. raw, etc... + * binary: BINARY, VARBINARY, BLOB, TINYBLOB, MEDIUMBLOB, LONGBLOB, bit. althought the concat_internal treat + * them specially, but the concat result is blob, so the result still affect by bytea_output. + * time: not ok, DateStyle will affect the result. time, timestamp, date, etc... + * num: ok, integer, float, numeric + * bool: ok + * string: ok, char/varchar/text/xml/json/set/enum/xml/unknown, etc... + */ + switch (typ) { + case BOOLOID: + case CHAROID: + case NAMEOID: + case INT1OID: + case INT2OID: + case INT4OID: + case INT8OID: + case INT16OID: + case TEXTOID: + case OIDOID: + case CLOBOID: + case JSONOID: + case XMLOID: + case UNKNOWNOID: + case VARCHAROID: + case VARBITOID: + case CSTRINGOID: + case JSONBOID: + case NVARCHAR2OID: + case XIDOID: + case SHORTXIDOID: + break; + default: + if (type_is_set(typ) || type_is_enum(typ)) { + break; + } + /* other case, return false directly */ + return false; + } + } + /* all args outfunc are immutable, return true */ + return true; + } + return false; } @@ -4295,7 +4345,7 @@ static Expr* evaluate_function(Oid funcid, Oid result_type, int32 result_typmod, /* okay */; else if (context->estimate && funcform->provolatile == PROVOLATILE_STABLE) /* okay */; - else if (is_safe_simplify_func(funcid)) + else if (is_safe_simplify_func(funcid, args)) /* okay */; else return NULL; diff --git a/src/test/regress/expected/stable_function_shippable.out b/src/test/regress/expected/stable_function_shippable.out index 8ab9f5fc1..c87bedb2e 100644 --- a/src/test/regress/expected/stable_function_shippable.out +++ b/src/test/regress/expected/stable_function_shippable.out @@ -778,3 +778,471 @@ explain (costs off, verbose on) select * from test where date_trunc('year', b) > --clean up drop table test; +create table concat_ws_t(a text); +-- test concat +explain(costs off) select * from concat_ws_t where a like concat('%', '1', '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::bool, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%t%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::"char", '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::name, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int1, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int2, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int4, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int8, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int16, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::text, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::oid, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::clob, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '{"a":1}'::json, '%'); + QUERY PLAN +------------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%{"a":1}%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::xml, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::varchar, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::varbit, '%')::text; + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::cstring, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '{"a":1}'::jsonb, '%'); + QUERY PLAN +------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ '%{"a": 1}%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::nvarchar2, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::xid, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::xid32, '%'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '%1%'::text) +(2 rows) + +-- some can't do simply func +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::money, '%'); + QUERY PLAN +--------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', '$1.00'::money, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::raw, '%'); + QUERY PLAN +---------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', '01'::raw, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::bytea, '%'); + QUERY PLAN +-------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', '\x31'::bytea, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '2022-11-11'::date, '%'); + QUERY PLAN +------------------------------------------------------------------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', '2022-11-11 00:00:00'::timestamp(0) without time zone, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '2022-11-11 11:11:11'::timestamp, '%'); + QUERY PLAN +--------------------------------------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', '2022-11-11 11:11:11'::timestamp without time zone, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '11:11:11'::time, '%'); + QUERY PLAN +----------------------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', '11:11:11'::time without time zone, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::numeric, '%'); + QUERY PLAN +----------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', 1::numeric, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::bpchar, '%'); + QUERY PLAN +------------------------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', '1'::bpchar, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::float4, '%'); + QUERY PLAN +-------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', 1::real, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::float8, '%'); + QUERY PLAN +-------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', 1::double precision, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::blob, '%')::text; + QUERY PLAN +----------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', '01'::blob, '%')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::bit(8), '%')::text; + QUERY PLAN +-------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat('%', B'10000000'::bit(8), '%')) +(2 rows) + +-- -- test concat_ws +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1', '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::bool, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ 't23'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::"char", '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::name, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int1, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int2, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int4, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int8, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int16, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::text, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::oid, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::clob, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '{"a":1}'::json, '3'); + QUERY PLAN +------------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '{"a":1}23'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::xml, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::varchar, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::varbit, '3')::text; + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::cstring, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '{"a":1}'::jsonb, '3'); + QUERY PLAN +------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ '{"a": 1}23'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::nvarchar2, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::xid, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::xid32, '3'); + QUERY PLAN +------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ '123'::text) +(2 rows) + +-- some can't do simply func +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::money, '3'); + QUERY PLAN +------------------------------------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, '$1.00'::money, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::raw, '3'); + QUERY PLAN +------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, '01'::raw, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::bytea, '3'); + QUERY PLAN +----------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, '\x31'::bytea, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '2022-11-11'::date, '3'); + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, '2022-11-11 00:00:00'::timestamp(0) without time zone, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '2022-11-11 11:11:11'::timestamp, '3'); + QUERY PLAN +------------------------------------------------------------------------------------------------ + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, '2022-11-11 11:11:11'::timestamp without time zone, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '11:11:11'::time, '3'); + QUERY PLAN +-------------------------------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, '11:11:11'::time without time zone, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::numeric, '3'); + QUERY PLAN +-------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, 1::numeric, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::bpchar, '3'); + QUERY PLAN +--------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, '1'::bpchar, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::float4, '3'); + QUERY PLAN +----------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, 1::real, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::float8, '3'); + QUERY PLAN +----------------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, 1::double precision, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::blob, '3')::text; + QUERY PLAN +-------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, '01'::blob, '3')) +(2 rows) + +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::bit(8), '3')::text; + QUERY PLAN +----------------------------------------------------------------- + Seq Scan on concat_ws_t + Filter: (a ~~ concat_ws('2'::text, B'10000000'::bit(8), '3')) +(2 rows) + +drop table concat_ws_t; diff --git a/src/test/regress/input/insert_right_ref.source b/src/test/regress/input/insert_right_ref.source index 0c999191f..91d803644 100644 --- a/src/test/regress/input/insert_right_ref.source +++ b/src/test/regress/input/insert_right_ref.source @@ -183,7 +183,7 @@ select (c6 is not null) as c6_is_not_null, (c12 is not null) as c12_is_not_null from time_default_t where n = 1 or n = 3; -select (c6 is not null) c6_is_not_null, +select (c6 is null) as c6_is_null, (c8 is null) as c8_is_null, (c10 is null) as c10_is_null, (c12 is null) as c12_is_null diff --git a/src/test/regress/output/insert_right_ref.source b/src/test/regress/output/insert_right_ref.source index fce52485f..3e5ea63bb 100644 --- a/src/test/regress/output/insert_right_ref.source +++ b/src/test/regress/output/insert_right_ref.source @@ -215,8 +215,8 @@ from num_default_t; ?column? | c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10 | c11 | c12 | c13 | c14 | c15 | c16 | c17 | c18 | c19 | c20 | c21 ----------+----+----+----+----+----+----+----+----+----+-----+-----+-----+-----+-----+--------+-----+-------+-----+-----+-----+------ 3 | 1 | | 3 | | 5 | | 7 | | 9 | 10 | | t | | 14 | 15.000 | 16 | 17.00 | 18 | | 10 | 2037 - 3 | 1 | | 3 | | 5 | | 7 | | 9 | 10 | | t | | 14 | 15.000 | 16 | 17.00 | 18 | | | 2037 - 3 | 1 | | 3 | | 5 | | 7 | | 9 | 10 | | t | | 14 | 15.000 | 16 | 17.00 | 18 | | | 2037 + 3 | 1 | | 3 | | 5 | | 7 | | 9 | 10 | | t | | 14 | 15.000 | 16 | 17.00 | 18 | | | + 3 | 1 | | 3 | | 5 | | 7 | | 9 | 10 | | t | | 14 | 15.000 | 16 | 17.00 | 18 | | | 3 | 1 | | 3 | | 5 | | 7 | | 9 | 10 | | t | | 14 | 15.000 | 16 | 17.00 | 18 | | 10 | 2037 (4 rows) @@ -308,14 +308,14 @@ from time_default_t where n = 1 or n = 3; t | t | t | t (2 rows) -select (c6 is not null) c6_is_not_null, +select (c6 is null) as c6_is_null, (c8 is null) as c8_is_null, (c10 is null) as c10_is_null, (c12 is null) as c12_is_null from time_default_t where n = 2; - c6_is_not_null | c8_is_null | c10_is_null | c12_is_null -----------------+------------+-------------+------------- - t | t | t | t + c6_is_null | c8_is_null | c10_is_null | c12_is_null +------------+------------+-------------+------------- + t | t | t | t (1 row) select (c1=c2) as c1c2, diff --git a/src/test/regress/sql/stable_function_shippable.sql b/src/test/regress/sql/stable_function_shippable.sql index 1ec825c57..d0fd1fbf5 100644 --- a/src/test/regress/sql/stable_function_shippable.sql +++ b/src/test/regress/sql/stable_function_shippable.sql @@ -329,3 +329,80 @@ explain (costs off, verbose on) select * from test where date_trunc('year', b) > --clean up drop table test; + +create table concat_ws_t(a text); +-- test concat +explain(costs off) select * from concat_ws_t where a like concat('%', '1', '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::bool, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::"char", '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::name, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int1, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int2, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int4, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int8, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::int16, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::text, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::oid, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::clob, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '{"a":1}'::json, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::xml, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::varchar, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::varbit, '%')::text; +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::cstring, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '{"a":1}'::jsonb, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::nvarchar2, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::xid, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::xid32, '%'); + +-- some can't do simply func +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::money, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::raw, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::bytea, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '2022-11-11'::date, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '2022-11-11 11:11:11'::timestamp, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '11:11:11'::time, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::numeric, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::bpchar, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::float4, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::float8, '%'); +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::blob, '%')::text; +explain(costs off) select * from concat_ws_t where a like concat('%', '1'::bit(8), '%')::text; + +-- -- test concat_ws +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1', '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::bool, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::"char", '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::name, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int1, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int2, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int4, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int8, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::int16, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::text, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::oid, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::clob, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '{"a":1}'::json, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::xml, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::varchar, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::varbit, '3')::text; +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::cstring, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '{"a":1}'::jsonb, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::nvarchar2, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::xid, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::xid32, '3'); + +-- some can't do simply func +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::money, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::raw, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::bytea, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '2022-11-11'::date, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '2022-11-11 11:11:11'::timestamp, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '11:11:11'::time, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::numeric, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::bpchar, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::float4, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::float8, '3'); +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::blob, '3')::text; +explain(costs off) select * from concat_ws_t where a like concat_ws('2', '1'::bit(8), '3')::text; + +drop table concat_ws_t;