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

Commitdcf3902

Browse files
committed
Make SubPlan nodes carry the result's typmod as well as datatype OID. This is
for consistency with the (relatively) recent addition of typmod to SubLink.An example of why it's a good idea is to be seen in the recent "failed tolocate grouping columns" bug, which wouldn't have happened if a SubPlanexposed the same typmod info as the SubLink it was derived from.This could be back-patched, since it doesn't affect any on-disk data format,but for the moment it doesn't seem necessary to do so.
1 parent4886dc9 commitdcf3902

File tree

6 files changed

+55
-26
lines changed

6 files changed

+55
-26
lines changed

‎src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.425 2009/02/25 03:30:37 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.426 2009/03/10 22:09:25 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1113,6 +1113,7 @@ _copySubPlan(SubPlan *from)
11131113
COPY_NODE_FIELD(paramIds);
11141114
COPY_SCALAR_FIELD(plan_id);
11151115
COPY_SCALAR_FIELD(firstColType);
1116+
COPY_SCALAR_FIELD(firstColTypmod);
11161117
COPY_SCALAR_FIELD(useHashTable);
11171118
COPY_SCALAR_FIELD(unknownEqFalse);
11181119
COPY_NODE_FIELD(setParam);

‎src/backend/nodes/equalfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Portions Copyright (c) 1994, Regents of the University of California
2323
*
2424
* IDENTIFICATION
25-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.349 2009/02/25 03:30:37 tgl Exp $
25+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.350 2009/03/10 22:09:25 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -342,6 +342,7 @@ _equalSubPlan(SubPlan *a, SubPlan *b)
342342
COMPARE_NODE_FIELD(paramIds);
343343
COMPARE_SCALAR_FIELD(plan_id);
344344
COMPARE_SCALAR_FIELD(firstColType);
345+
COMPARE_SCALAR_FIELD(firstColTypmod);
345346
COMPARE_SCALAR_FIELD(useHashTable);
346347
COMPARE_SCALAR_FIELD(unknownEqFalse);
347348
COMPARE_NODE_FIELD(setParam);

‎src/backend/nodes/nodeFuncs.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.38 2009/02/25 03:30:37 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.39 2009/03/10 22:09:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -28,7 +28,7 @@ static intleftmostLoc(int loc1, int loc2);
2828

2929
/*
3030
*exprType -
31-
* returns the Oid of the type of the expression. (Used for typechecking.)
31+
* returns the Oid of the type of the expression's result.
3232
*/
3333
Oid
3434
exprType(Node*expr)
@@ -117,11 +117,6 @@ exprType(Node *expr)
117117
break;
118118
caseT_SubPlan:
119119
{
120-
/*
121-
* Although the parser does not ever deal with already-planned
122-
* expression trees, we support SubPlan nodes in this routine
123-
* for the convenience of ruleutils.c.
124-
*/
125120
SubPlan*subplan= (SubPlan*)expr;
126121

127122
if (subplan->subLinkType==EXPR_SUBLINK||
@@ -148,7 +143,6 @@ exprType(Node *expr)
148143
break;
149144
caseT_AlternativeSubPlan:
150145
{
151-
/* As above, supported for the convenience of ruleutils.c */
152146
AlternativeSubPlan*asplan= (AlternativeSubPlan*)expr;
153147

154148
/* subplans should all return the same thing */
@@ -236,8 +230,8 @@ exprType(Node *expr)
236230

237231
/*
238232
*exprTypmod -
239-
* returns the type-specificattrmod of the expression, if it can be
240-
* determined. Inmost cases, it can't and we return -1.
233+
* returns the type-specificmodifier of the expression's result type,
234+
*if it can bedetermined. Inmany cases, it can't and we return -1.
241235
*/
242236
int32
243237
exprTypmod(Node*expr)
@@ -286,6 +280,32 @@ exprTypmod(Node *expr)
286280
}
287281
}
288282
break;
283+
caseT_SubPlan:
284+
{
285+
SubPlan*subplan= (SubPlan*)expr;
286+
287+
if (subplan->subLinkType==EXPR_SUBLINK||
288+
subplan->subLinkType==ARRAY_SUBLINK)
289+
{
290+
/* get the typmod of the subselect's first target column */
291+
/* note we don't need to care if it's an array */
292+
returnsubplan->firstColTypmod;
293+
}
294+
else
295+
{
296+
/* for all other subplan types, result is boolean */
297+
return-1;
298+
}
299+
}
300+
break;
301+
caseT_AlternativeSubPlan:
302+
{
303+
AlternativeSubPlan*asplan= (AlternativeSubPlan*)expr;
304+
305+
/* subplans should all return the same thing */
306+
returnexprTypmod((Node*)linitial(asplan->subplans));
307+
}
308+
break;
289309
caseT_FieldSelect:
290310
return ((FieldSelect*)expr)->resulttypmod;
291311
caseT_RelabelType:

‎src/backend/nodes/outfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.353 2009/02/25 03:30:37 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.354 2009/03/10 22:09:25 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -957,6 +957,7 @@ _outSubPlan(StringInfo str, SubPlan *node)
957957
WRITE_NODE_FIELD(paramIds);
958958
WRITE_INT_FIELD(plan_id);
959959
WRITE_OID_FIELD(firstColType);
960+
WRITE_INT_FIELD(firstColTypmod);
960961
WRITE_BOOL_FIELD(useHashTable);
961962
WRITE_BOOL_FIELD(unknownEqFalse);
962963
WRITE_NODE_FIELD(setParam);

‎src/backend/optimizer/plan/subselect.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.146 2009/02/25 03:30:37 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.147 2009/03/10 22:09:26 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -229,13 +229,13 @@ SS_assign_worktable_param(PlannerInfo *root)
229229
/*
230230
* Get the datatype of the first column of the plan's output.
231231
*
232-
* This is stored for ARRAY_SUBLINK and for exprType(), which doesn't have any
233-
* way to get at the plan associated with a SubPlan node. We really only need
234-
* thevalue for EXPR_SUBLINK and ARRAY_SUBLINK subplans, but for consistency
235-
* weset it always.
232+
* This is stored for ARRAY_SUBLINKexecutionand for exprType()/exprTypmod(),
233+
*which have noway to get at the plan associated with a SubPlan node.
234+
*We really only needtheinfo for EXPR_SUBLINK and ARRAY_SUBLINK subplans,
235+
*but for consistencywesave it always.
236236
*/
237-
staticOid
238-
get_first_col_type(Plan*plan)
237+
staticvoid
238+
get_first_col_type(Plan*plan,Oid*coltype,int32*coltypmod)
239239
{
240240
/* In cases such as EXISTS, tlist might be empty; arbitrarily use VOID */
241241
if (plan->targetlist)
@@ -244,9 +244,14 @@ get_first_col_type(Plan *plan)
244244

245245
Assert(IsA(tent,TargetEntry));
246246
if (!tent->resjunk)
247-
returnexprType((Node*)tent->expr);
247+
{
248+
*coltype=exprType((Node*)tent->expr);
249+
*coltypmod=exprTypmod((Node*)tent->expr);
250+
return;
251+
}
248252
}
249-
returnVOIDOID;
253+
*coltype=VOIDOID;
254+
*coltypmod=-1;
250255
}
251256

252257
/*
@@ -414,7 +419,7 @@ build_subplan(PlannerInfo *root, Plan *plan, List *rtable,
414419
splan->subLinkType=subLinkType;
415420
splan->testexpr=NULL;
416421
splan->paramIds=NIL;
417-
splan->firstColType=get_first_col_type(plan);
422+
get_first_col_type(plan,&splan->firstColType,&splan->firstColTypmod);
418423
splan->useHashTable= false;
419424
splan->unknownEqFalse=unknownEqFalse;
420425
splan->setParam=NIL;
@@ -876,7 +881,7 @@ SS_process_ctes(PlannerInfo *root)
876881
splan->subLinkType=CTE_SUBLINK;
877882
splan->testexpr=NULL;
878883
splan->paramIds=NIL;
879-
splan->firstColType=get_first_col_type(plan);
884+
get_first_col_type(plan,&splan->firstColType,&splan->firstColTypmod);
880885
splan->useHashTable= false;
881886
splan->unknownEqFalse= false;
882887
splan->setParam=NIL;
@@ -2111,7 +2116,7 @@ SS_make_initplan_from_plan(PlannerInfo *root, Plan *plan,
21112116
*/
21122117
node=makeNode(SubPlan);
21132118
node->subLinkType=EXPR_SUBLINK;
2114-
node->firstColType=get_first_col_type(plan);
2119+
get_first_col_type(plan,&node->firstColType,&node->firstColTypmod);
21152120
node->plan_id=list_length(root->glob->subplans);
21162121

21172122
root->init_plans=lappend(root->init_plans,node);

‎src/include/nodes/primnodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.146 2009/02/25 03:30:37 tgl Exp $
13+
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.147 2009/03/10 22:09:26 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -504,6 +504,7 @@ typedef struct SubPlan
504504
intplan_id;/* Index (from 1) in PlannedStmt.subplans */
505505
/* Extra data useful for determining subplan's output type: */
506506
OidfirstColType;/* Type of first column of subplan result */
507+
int32firstColTypmod;/* Typmod of first column of subplan result */
507508
/* Information about execution strategy: */
508509
booluseHashTable;/* TRUE to store subselect output in a hash
509510
* table (implies we are doing "IN") */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp