!4491 修复I8HWKW所示的断言问题

Merge pull request !4491 from wangfeihuo/master
This commit is contained in:
opengauss_bot
2023-11-24 08:58:52 +00:00
committed by Gitee
5 changed files with 128 additions and 6 deletions

View File

@ -1393,6 +1393,7 @@ static Node* transformAExprOp(ParseState* pstate, A_Expr* a)
static Node* transformAExprAnd(ParseState* pstate, A_Expr* a)
{
a->rexpr = (Node *)copyObject(a->rexpr);
Node* lexpr = transformExprRecurse(pstate, a->lexpr);
Node* rexpr = transformExprRecurse(pstate, a->rexpr);

View File

@ -1925,12 +1925,6 @@ static void inline_cte(PlannerInfo *root, CommonTableExpr *cte)
(void) inline_cte_walker((Node*)root->parse, &context);
/*
* We would expect the reference number to be zero after inline, however, the
* reference count of cte are not accurate for re-entry issues at parsing stage
* Until fixed, we only check for non-negative refcnt result.
*/
Assert(context.refcount >= 0);
/* Mark this CTE as inlined */
cte->cterefcount = -1;
}

View File

@ -0,0 +1,81 @@
-- create table
create table t_cte(a int, b int);
insert into t_cte select generate_series(1,5), generate_series(1,5);
create table int8_tbl (q1 int8, q2 int8);
INSERT INTO INT8_TBL VALUES
(' 123 ',' 456');
-- check case where CTE reference is removed due to optimization
EXPLAIN (VERBOSE, COSTS OFF)
SELECT q1 FROM
(
WITH t_cte AS (SELECT * FROM int8_tbl t)
SELECT q1, (SELECT q2 FROM t_cte WHERE t_cte.q1 = i8.q1) AS t_sub
FROM int8_tbl i8
) ss;
QUERY PLAN
---------------------------------------------
Subquery Scan on ss
Output: ss.q1
-> Seq Scan on public.int8_tbl i8
Output: i8.q1, (SubPlan 2)
CTE t_cte
-> Seq Scan on public.int8_tbl t
Output: t.q1, t.q2
SubPlan 2
-> CTE Scan on t_cte
Output: t_cte.q2
Filter: (t_cte.q1 = i8.q1)
(11 rows)
SELECT q1 FROM
(
WITH t_cte AS (SELECT * FROM int8_tbl t)
SELECT q1, (SELECT q2 FROM t_cte WHERE t_cte.q1 = i8.q1) AS t_sub
FROM int8_tbl i8
) ss;
q1
-----
123
(1 row)
EXPLAIN (VERBOSE, COSTS OFF)
SELECT q1 FROM
(
WITH t_cte AS MATERIALIZED (SELECT * FROM int8_tbl t)
SELECT q1, (SELECT q2 FROM t_cte WHERE t_cte.q1 = i8.q1) AS t_sub
FROM int8_tbl i8
) ss;
QUERY PLAN
---------------------------------------------
Subquery Scan on ss
Output: ss.q1
-> Seq Scan on public.int8_tbl i8
Output: i8.q1, (SubPlan 2)
CTE t_cte
-> Seq Scan on public.int8_tbl t
Output: t.q1, t.q2
SubPlan 2
-> CTE Scan on t_cte
Output: t_cte.q2
Filter: (t_cte.q1 = i8.q1)
(11 rows)
SELECT q1 FROM
(
WITH t_cte AS MATERIALIZED (SELECT * FROM int8_tbl t)
SELECT q1, (SELECT q2 FROM t_cte WHERE t_cte.q1 = i8.q1) AS t_sub
FROM int8_tbl i8
) ss;
q1
-----
123
(1 row)
SELECT ( WITH table2 AS NOT MATERIALIZED ( SELECT 1 ) SELECT 1 FROM ( SELECT ( SELECT 1 FROM table2 ) BETWEEN 1 AND 1 ) AS alias6 ) ;
?column?
----------
1
(1 row)
drop table t_cte;
drop table int8_tbl cascade;

View File

@ -328,6 +328,7 @@ test: hw_pct_type_and_rowtype
#test: create_basetype
#test: tabletype
#test with recursive
test: with_002
test: recursive_ref_recursive
#test: recursive_prepare
#test: recursive_cte

View File

@ -0,0 +1,45 @@
-- create table
create table t_cte(a int, b int);
insert into t_cte select generate_series(1,5), generate_series(1,5);
create table int8_tbl (q1 int8, q2 int8);
INSERT INTO INT8_TBL VALUES
(' 123 ',' 456');
-- check case where CTE reference is removed due to optimization
EXPLAIN (VERBOSE, COSTS OFF)
SELECT q1 FROM
(
WITH t_cte AS (SELECT * FROM int8_tbl t)
SELECT q1, (SELECT q2 FROM t_cte WHERE t_cte.q1 = i8.q1) AS t_sub
FROM int8_tbl i8
) ss;
SELECT q1 FROM
(
WITH t_cte AS (SELECT * FROM int8_tbl t)
SELECT q1, (SELECT q2 FROM t_cte WHERE t_cte.q1 = i8.q1) AS t_sub
FROM int8_tbl i8
) ss;
EXPLAIN (VERBOSE, COSTS OFF)
SELECT q1 FROM
(
WITH t_cte AS MATERIALIZED (SELECT * FROM int8_tbl t)
SELECT q1, (SELECT q2 FROM t_cte WHERE t_cte.q1 = i8.q1) AS t_sub
FROM int8_tbl i8
) ss;
SELECT q1 FROM
(
WITH t_cte AS MATERIALIZED (SELECT * FROM int8_tbl t)
SELECT q1, (SELECT q2 FROM t_cte WHERE t_cte.q1 = i8.q1) AS t_sub
FROM int8_tbl i8
) ss;
SELECT ( WITH table2 AS NOT MATERIALIZED ( SELECT 1 ) SELECT 1 FROM ( SELECT ( SELECT 1 FROM table2 ) BETWEEN 1 AND 1 ) AS alias6 ) ;
drop table t_cte;
drop table int8_tbl cascade;