Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b8d45d

Browse files
committed
Fix Assert failure in WITH RECURSIVE UNION queries
If the non-recursive part of a recursive CTE ended up usingTTSOpsBufferHeapTuple as the table slot type, then a duplicate valuecould cause an Assert failure in CheckOpSlotCompatibility() whenchecking the hash table for the duplicate value. The expected slot typefor the deform step was TTSOpsMinimalTuple so the Assert failed when theTTSOpsBufferHeapTuple slot was used.This is a long-standing bug which we likely didn't notice because itseems much more likely that the non-recursive term would have requiredprojection and used a TTSOpsVirtual slot, which CheckOpSlotCompatibilityis ok with.There doesn't seem to be any harm done here other than the Assertfailure. Both TTSOpsMinimalTuple and TTSOpsBufferHeapTuple slot typesrequire tuple deformation, so the EEOP_*_FETCHSOME ExprState step wouldhave properly existed in the ExprState.The solution is to pass NULL for the ExecBuildGroupingEqual's 'lops'parameter. This means the ExprState's EEOP_*_FETCHSOME step won'texpect a fixed slot type. This makes CheckOpSlotCompatibility() happy asno checking is performed when the ExprEvalStep is not expecting a fixedslot type.Reported-by: Richard GuoReviewed-by: Tom LaneDiscussion:https://postgr.es/m/CAMbWs4-8U9q2LAtf8+ghV11zeUReA3AmrYkxzBEv0vKnDxwkKA@mail.gmail.comBackpatch-through: 13, all supported versions
1 parent04b8601 commit7b8d45d

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

‎src/backend/executor/execGrouping.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,8 @@ BuildTupleHashTableExt(PlanState *parent,
224224
allow_jit=metacxt!=tablecxt;
225225

226226
/* build comparator for all columns */
227-
/* XXX: should we support non-minimal tuples for the inputslot? */
228227
hashtable->tab_eq_func=ExecBuildGroupingEqual(inputDesc,inputDesc,
229-
&TTSOpsMinimalTuple,&TTSOpsMinimalTuple,
228+
NULL,&TTSOpsMinimalTuple,
230229
numCols,
231230
keyColIdx,eqfuncoids,collations,
232231
allow_jit ?parent :NULL);

‎src/test/regress/expected/with.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,21 @@ SELECT t1.id, t2.path, t2 FROM t AS t1 JOIN t AS t2 ON
636636
16 | {3,7,11,16} | (16,"{3,7,11,16}")
637637
(16 rows)
638638

639+
CREATE TEMP TABLE duplicates (a INT NOT NULL);
640+
INSERT INTO duplicates VALUES(1), (1);
641+
-- Try out a recursive UNION case where the non-recursive part's table slot
642+
-- uses TTSOpsBufferHeapTuple and contains duplicate rows.
643+
WITH RECURSIVE cte (a) as (
644+
SELECT a FROM duplicates
645+
UNION
646+
SELECT a FROM cte
647+
)
648+
SELECT a FROM cte;
649+
a
650+
---
651+
1
652+
(1 row)
653+
639654
-- test that column statistics from a materialized CTE are available
640655
-- to upper planner (otherwise, we'd get a stupider plan)
641656
explain (costs off)

‎src/test/regress/sql/with.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,18 @@ UNION ALL
347347
SELECTt1.id,t2.path, t2FROM tAS t1JOIN tAS t2ON
348348
(t1.id=t2.id);
349349

350+
CREATE TEMP TABLE duplicates (aINTNOT NULL);
351+
INSERT INTO duplicatesVALUES(1), (1);
352+
353+
-- Try out a recursive UNION case where the non-recursive part's table slot
354+
-- uses TTSOpsBufferHeapTuple and contains duplicate rows.
355+
WITH RECURSIVE cte (a)as (
356+
SELECT aFROM duplicates
357+
UNION
358+
SELECT aFROM cte
359+
)
360+
SELECT aFROM cte;
361+
350362
-- test that column statistics from a materialized CTE are available
351363
-- to upper planner (otherwise, we'd get a stupider plan)
352364
explain (costs off)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp