~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/backend/parser/parse_relation.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 *
10
10
 * IDENTIFICATION
11
 
 *        $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.141 2009/01/22 20:16:05 tgl Exp $
 
11
 *        $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.142 2009/06/11 14:49:00 momjian Exp $
12
12
 *
13
13
 *-------------------------------------------------------------------------
14
14
 */
38
38
static RangeTblEntry *scanNameSpaceForRefname(ParseState *pstate,
39
39
                                                const char *refname, int location);
40
40
static RangeTblEntry *scanNameSpaceForRelid(ParseState *pstate, Oid relid,
41
 
                                                                                        int location);
 
41
                                          int location);
42
42
static void markRTEForSelectPriv(ParseState *pstate, RangeTblEntry *rte,
43
 
                                                                 int rtindex, AttrNumber col);
 
43
                                         int rtindex, AttrNumber col);
44
44
static bool isLockedRel(ParseState *pstate, char *refname);
45
45
static void expandRelation(Oid relid, Alias *eref,
46
46
                           int rtindex, int sublevels_up,
194
194
scanNameSpaceForCTE(ParseState *pstate, const char *refname,
195
195
                                        Index *ctelevelsup)
196
196
{
197
 
        Index   levelsup;
 
197
        Index           levelsup;
198
198
 
199
199
        for (levelsup = 0;
200
200
                 pstate != NULL;
201
201
                 pstate = pstate->parentParseState, levelsup++)
202
202
        {
203
 
                ListCell *lc;
 
203
                ListCell   *lc;
204
204
 
205
205
                foreach(lc, pstate->p_ctenamespace)
206
206
                {
226
226
{
227
227
        for (; pstate != NULL; pstate = pstate->parentParseState)
228
228
        {
229
 
                ListCell *lc;
 
229
                ListCell   *lc;
230
230
 
231
231
                foreach(lc, pstate->p_future_ctes)
232
232
                {
264
264
        Index           levelsup;
265
265
 
266
266
        /*
267
 
         * If it's an unqualified name, check for possible CTE matches.
268
 
         * A CTE hides any real relation matches.  If no CTE, look for
269
 
         * a matching relation.
 
267
         * If it's an unqualified name, check for possible CTE matches. A CTE
 
268
         * hides any real relation matches.  If no CTE, look for a matching
 
269
         * relation.
270
270
         */
271
271
        if (!relation->schemaname)
272
272
                cte = scanNameSpaceForCTE(pstate, refname, &ctelevelsup);
616
616
                rte->requiredPerms |= ACL_SELECT;
617
617
                /* Must offset the attnum to fit in a bitmapset */
618
618
                rte->selectedCols = bms_add_member(rte->selectedCols,
619
 
                                                                        col - FirstLowInvalidHeapAttributeNumber);
 
619
                                                                   col - FirstLowInvalidHeapAttributeNumber);
620
620
        }
621
621
        else if (rte->rtekind == RTE_JOIN)
622
622
        {
623
623
                if (col == InvalidAttrNumber)
624
624
                {
625
625
                        /*
626
 
                         * A whole-row reference to a join has to be treated as
627
 
                         * whole-row references to the two inputs.
 
626
                         * A whole-row reference to a join has to be treated as whole-row
 
627
                         * references to the two inputs.
628
628
                         */
629
629
                        JoinExpr   *j;
630
630
 
639
639
                        /* Note: we can't see FromExpr here */
640
640
                        if (IsA(j->larg, RangeTblRef))
641
641
                        {
642
 
                                int             varno = ((RangeTblRef *) j->larg)->rtindex;
 
642
                                int                     varno = ((RangeTblRef *) j->larg)->rtindex;
643
643
 
644
644
                                markRTEForSelectPriv(pstate, NULL, varno, InvalidAttrNumber);
645
645
                        }
646
646
                        else if (IsA(j->larg, JoinExpr))
647
647
                        {
648
 
                                int             varno = ((JoinExpr *) j->larg)->rtindex;
 
648
                                int                     varno = ((JoinExpr *) j->larg)->rtindex;
649
649
 
650
650
                                markRTEForSelectPriv(pstate, NULL, varno, InvalidAttrNumber);
651
651
                        }
654
654
                                         (int) nodeTag(j->larg));
655
655
                        if (IsA(j->rarg, RangeTblRef))
656
656
                        {
657
 
                                int             varno = ((RangeTblRef *) j->rarg)->rtindex;
 
657
                                int                     varno = ((RangeTblRef *) j->rarg)->rtindex;
658
658
 
659
659
                                markRTEForSelectPriv(pstate, NULL, varno, InvalidAttrNumber);
660
660
                        }
661
661
                        else if (IsA(j->rarg, JoinExpr))
662
662
                        {
663
 
                                int             varno = ((JoinExpr *) j->rarg)->rtindex;
 
663
                                int                     varno = ((JoinExpr *) j->rarg)->rtindex;
664
664
 
665
665
                                markRTEForSelectPriv(pstate, NULL, varno, InvalidAttrNumber);
666
666
                        }
676
676
                         * The aliasvar could be either a Var or a COALESCE expression,
677
677
                         * but in the latter case we should already have marked the two
678
678
                         * referent variables as being selected, due to their use in the
679
 
                         * JOIN clause.  So we need only be concerned with the simple
680
 
                         * Var case.
 
679
                         * JOIN clause.  So we need only be concerned with the simple Var
 
680
                         * case.
681
681
                         */
682
 
                        Var        *aliasvar;
 
682
                        Var                *aliasvar;
683
683
 
684
684
                        Assert(col > 0 && col <= list_length(rte->joinaliasvars));
685
685
                        aliasvar = (Var *) list_nth(rte->joinaliasvars, col - 1);
700
700
void
701
701
markVarForSelectPriv(ParseState *pstate, Var *var, RangeTblEntry *rte)
702
702
{
703
 
        Index   lv;
 
703
        Index           lv;
704
704
 
705
705
        Assert(IsA(var, Var));
706
706
        /* Find the appropriate pstate if it's an uplevel Var */
1325
1325
        int                     numaliases;
1326
1326
 
1327
1327
        /*
1328
 
         * Fail if join has too many columns --- we must be able to reference
1329
 
         * any of the columns with an AttrNumber.
 
1328
         * Fail if join has too many columns --- we must be able to reference any
 
1329
         * of the columns with an AttrNumber.
1330
1330
         */
1331
1331
        if (list_length(aliasvars) > MaxAttrNumber)
1332
1332
                ereport(ERROR,
1816
1816
                                varattno = 0;
1817
1817
                                forboth(lct, rte->ctecoltypes, lcm, rte->ctecoltypmods)
1818
1818
                                {
1819
 
                                        Oid             coltype = lfirst_oid(lct);
1820
 
                                        int32   coltypmod = lfirst_int(lcm);
 
1819
                                        Oid                     coltype = lfirst_oid(lct);
 
1820
                                        int32           coltypmod = lfirst_int(lcm);
1821
1821
 
1822
1822
                                        varattno++;
1823
1823
 
1971
1971
                markVarForSelectPriv(pstate, varnode, rte);
1972
1972
        }
1973
1973
 
1974
 
        Assert(name == NULL && var == NULL);    /* lists not the same length? */
 
1974
        Assert(name == NULL && var == NULL);            /* lists not the same length? */
1975
1975
 
1976
1976
        return te_list;
1977
1977
}
2457
2457
                if (rte)
2458
2458
                        ereport(ERROR,
2459
2459
                                        (errcode(ERRCODE_UNDEFINED_TABLE),
2460
 
                                         errmsg("invalid reference to FROM-clause entry for table \"%s\"",
2461
 
                                                        relation->relname),
 
2460
                        errmsg("invalid reference to FROM-clause entry for table \"%s\"",
 
2461
                                   relation->relname),
2462
2462
                                         (badAlias ?
2463
2463
                        errhint("Perhaps you meant to reference the table alias \"%s\".",
2464
2464
                                        badAlias) :