Skip to content

Commit b281ea8

Browse files
committed
Whole-row references were broken for subqueries and functions, because
attr_needed/attr_widths optimization failed to allow for Vars with attno zero in this case. Per report from Tatsuo Ishii.
1 parent 918b158 commit b281ea8

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/backend/optimizer/util/relnode.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.53 2003/11/29 19:51:51 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.54 2003/12/08 18:19:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -161,7 +161,8 @@ make_base_rel(Query *root, int relid)
161161
case RTE_SUBQUERY:
162162
case RTE_FUNCTION:
163163
/* Subquery or function --- need only set up attr range */
164-
rel->min_attr = 1;
164+
/* Note: 0 is included in range to support whole-row Vars */
165+
rel->min_attr = 0;
165166
rel->max_attr = length(rte->eref->colnames);
166167
break;
167168
default:
@@ -170,18 +171,11 @@ make_base_rel(Query *root, int relid)
170171
break;
171172
}
172173

173-
if (rel->max_attr >= rel->min_attr)
174-
{
175-
rel->attr_needed = (Relids *)
176-
palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
177-
rel->attr_widths = (int32 *)
178-
palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
179-
}
180-
else
181-
{
182-
rel->attr_needed = NULL;
183-
rel->attr_widths = NULL;
184-
}
174+
Assert(rel->max_attr >= rel->min_attr);
175+
rel->attr_needed = (Relids *)
176+
palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
177+
rel->attr_widths = (int32 *)
178+
palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
185179

186180
return rel;
187181
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy