LCOV - code coverage report
Current view: top level - src/backend/commands - view.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13beta1 Lines: 139 149 93.3 %
Date: 2020-06-01 07:06:57 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * view.c
       4             :  *    use rewrite rules to construct views
       5             :  *
       6             :  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
       7             :  * Portions Copyright (c) 1994, Regents of the University of California
       8             :  *
       9             :  *
      10             :  * IDENTIFICATION
      11             :  *    src/backend/commands/view.c
      12             :  *
      13             :  *-------------------------------------------------------------------------
      14             :  */
      15             : #include "postgres.h"
      16             : 
      17             : #include "access/relation.h"
      18             : #include "access/xact.h"
      19             : #include "catalog/namespace.h"
      20             : #include "commands/defrem.h"
      21             : #include "commands/tablecmds.h"
      22             : #include "commands/view.h"
      23             : #include "miscadmin.h"
      24             : #include "nodes/makefuncs.h"
      25             : #include "nodes/nodeFuncs.h"
      26             : #include "parser/analyze.h"
      27             : #include "parser/parse_relation.h"
      28             : #include "rewrite/rewriteDefine.h"
      29             : #include "rewrite/rewriteHandler.h"
      30             : #include "rewrite/rewriteManip.h"
      31             : #include "rewrite/rewriteSupport.h"
      32             : #include "utils/acl.h"
      33             : #include "utils/builtins.h"
      34             : #include "utils/lsyscache.h"
      35             : #include "utils/rel.h"
      36             : #include "utils/syscache.h"
      37             : 
      38             : static void checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc);
      39             : 
      40             : /*---------------------------------------------------------------------
      41             :  * DefineVirtualRelation
      42             :  *
      43             :  * Create a view relation and use the rules system to store the query
      44             :  * for the view.
      45             :  *
      46             :  * EventTriggerAlterTableStart must have been called already.
      47             :  *---------------------------------------------------------------------
      48             :  */
      49             : static ObjectAddress
      50       47374 : DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
      51             :                       List *options, Query *viewParse)
      52             : {
      53             :     Oid         viewOid;
      54             :     LOCKMODE    lockmode;
      55       47374 :     CreateStmt *createStmt = makeNode(CreateStmt);
      56             :     List       *attrList;
      57             :     ListCell   *t;
      58             : 
      59             :     /*
      60             :      * create a list of ColumnDef nodes based on the names and types of the
      61             :      * (non-junk) targetlist items from the view's SELECT list.
      62             :      */
      63       47374 :     attrList = NIL;
      64      510558 :     foreach(t, tlist)
      65             :     {
      66      463184 :         TargetEntry *tle = (TargetEntry *) lfirst(t);
      67             : 
      68      463184 :         if (!tle->resjunk)
      69             :         {
      70      460282 :             ColumnDef  *def = makeColumnDef(tle->resname,
      71      460282 :                                             exprType((Node *) tle->expr),
      72      460282 :                                             exprTypmod((Node *) tle->expr),
      73      460282 :                                             exprCollation((Node *) tle->expr));
      74             : 
      75             :             /*
      76             :              * It's possible that the column is of a collatable type but the
      77             :              * collation could not be resolved, so double-check.
      78             :              */
      79      460282 :             if (type_is_collatable(exprType((Node *) tle->expr)))
      80             :             {
      81      276716 :                 if (!OidIsValid(def->collOid))
      82           0 :                     ereport(ERROR,
      83             :                             (errcode(ERRCODE_INDETERMINATE_COLLATION),
      84             :                              errmsg("could not determine which collation to use for view column \"%s\"",
      85             :                                     def->colname),
      86             :                              errhint("Use the COLLATE clause to set the collation explicitly.")));
      87             :             }
      88             :             else
      89             :                 Assert(!OidIsValid(def->collOid));
      90             : 
      91      460282 :             attrList = lappend(attrList, def);
      92             :         }
      93             :     }
      94             : 
      95             :     /*
      96             :      * Look up, check permissions on, and lock the creation namespace; also
      97             :      * check for a preexisting view with the same name.  This will also set
      98             :      * relation->relpersistence to RELPERSISTENCE_TEMP if the selected
      99             :      * namespace is temporary.
     100             :      */
     101       47374 :     lockmode = replace ? AccessExclusiveLock : NoLock;
     102       47374 :     (void) RangeVarGetAndCheckCreationNamespace(relation, lockmode, &viewOid);
     103             : 
     104       47366 :     if (OidIsValid(viewOid) && replace)
     105             :     {
     106             :         Relation    rel;
     107             :         TupleDesc   descriptor;
     108         126 :         List       *atcmds = NIL;
     109             :         AlterTableCmd *atcmd;
     110             :         ObjectAddress address;
     111             : 
     112             :         /* Relation is already locked, but we must build a relcache entry. */
     113         126 :         rel = relation_open(viewOid, NoLock);
     114             : 
     115             :         /* Make sure it *is* a view. */
     116         126 :         if (rel->rd_rel->relkind != RELKIND_VIEW)
     117           0 :             ereport(ERROR,
     118             :                     (errcode(ERRCODE_WRONG_OBJECT_TYPE),
     119             :                      errmsg("\"%s\" is not a view",
     120             :                             RelationGetRelationName(rel))));
     121             : 
     122             :         /* Also check it's not in use already */
     123         126 :         CheckTableNotInUse(rel, "CREATE OR REPLACE VIEW");
     124             : 
     125             :         /*
     126             :          * Due to the namespace visibility rules for temporary objects, we
     127             :          * should only end up replacing a temporary view with another
     128             :          * temporary view, and similarly for permanent views.
     129             :          */
     130             :         Assert(relation->relpersistence == rel->rd_rel->relpersistence);
     131             : 
     132             :         /*
     133             :          * Create a tuple descriptor to compare against the existing view, and
     134             :          * verify that the old column list is an initial prefix of the new
     135             :          * column list.
     136             :          */
     137         126 :         descriptor = BuildDescForRelation(attrList);
     138         126 :         checkViewTupleDesc(descriptor, rel->rd_att);
     139             : 
     140             :         /*
     141             :          * If new attributes have been added, we must add pg_attribute entries
     142             :          * for them.  It is convenient (although overkill) to use the ALTER
     143             :          * TABLE ADD COLUMN infrastructure for this.
     144             :          *
     145             :          * Note that we must do this before updating the query for the view,
     146             :          * since the rules system requires that the correct view columns be in
     147             :          * place when defining the new rules.
     148             :          *
     149             :          * Also note that ALTER TABLE doesn't run parse transformation on
     150             :          * AT_AddColumnToView commands.  The ColumnDef we supply must be ready
     151             :          * to execute as-is.
     152             :          */
     153         114 :         if (list_length(attrList) > rel->rd_att->natts)
     154             :         {
     155             :             ListCell   *c;
     156          12 :             int         skip = rel->rd_att->natts;
     157             : 
     158          44 :             foreach(c, attrList)
     159             :             {
     160          32 :                 if (skip > 0)
     161             :                 {
     162          20 :                     skip--;
     163          20 :                     continue;
     164             :                 }
     165          12 :                 atcmd = makeNode(AlterTableCmd);
     166          12 :                 atcmd->subtype = AT_AddColumnToView;
     167          12 :                 atcmd->def = (Node *) lfirst(c);
     168          12 :                 atcmds = lappend(atcmds, atcmd);
     169             :             }
     170             : 
     171             :             /* EventTriggerAlterTableStart called by ProcessUtilitySlow */
     172          12 :             AlterTableInternal(viewOid, atcmds, true);
     173             : 
     174             :             /* Make the new view columns visible */
     175          12 :             CommandCounterIncrement();
     176             :         }
     177             : 
     178             :         /*
     179             :          * Update the query for the view.
     180             :          *
     181             :          * Note that we must do this before updating the view options, because
     182             :          * the new options may not be compatible with the old view query (for
     183             :          * example if we attempt to add the WITH CHECK OPTION, we require that
     184             :          * the new view be automatically updatable, but the old view may not
     185             :          * have been).
     186             :          */
     187         114 :         StoreViewQuery(viewOid, viewParse, replace);
     188             : 
     189             :         /* Make the new view query visible */
     190         114 :         CommandCounterIncrement();
     191             : 
     192             :         /*
     193             :          * Finally update the view options.
     194             :          *
     195             :          * The new options list replaces the existing options list, even if
     196             :          * it's empty.
     197             :          */
     198         114 :         atcmd = makeNode(AlterTableCmd);
     199         114 :         atcmd->subtype = AT_ReplaceRelOptions;
     200         114 :         atcmd->def = (Node *) options;
     201         114 :         atcmds = list_make1(atcmd);
     202             : 
     203             :         /* EventTriggerAlterTableStart called by ProcessUtilitySlow */
     204         114 :         AlterTableInternal(viewOid, atcmds, true);
     205             : 
     206         114 :         ObjectAddressSet(address, RelationRelationId, viewOid);
     207             : 
     208             :         /*
     209             :          * Seems okay, so return the OID of the pre-existing view.
     210             :          */
     211         114 :         relation_close(rel, NoLock);    /* keep the lock! */
     212             : 
     213         114 :         return address;
     214             :     }
     215             :     else
     216             :     {
     217             :         ObjectAddress address;
     218             : 
     219             :         /*
     220             :          * Set the parameters for keys/inheritance etc. All of these are
     221             :          * uninteresting for views...
     222             :          */
     223       47240 :         createStmt->relation = relation;
     224       47240 :         createStmt->tableElts = attrList;
     225       47240 :         createStmt->inhRelations = NIL;
     226       47240 :         createStmt->constraints = NIL;
     227       47240 :         createStmt->options = options;
     228       47240 :         createStmt->oncommit = ONCOMMIT_NOOP;
     229       47240 :         createStmt->tablespacename = NULL;
     230       47240 :         createStmt->if_not_exists = false;
     231             : 
     232             :         /*
     233             :          * Create the relation (this will error out if there's an existing
     234             :          * view, so we don't need more code to complain if "replace" is
     235             :          * false).
     236             :          */
     237       47240 :         address = DefineRelation(createStmt, RELKIND_VIEW, InvalidOid, NULL,
     238             :                                  NULL);
     239             :         Assert(address.objectId != InvalidOid);
     240             : 
     241             :         /* Make the new view relation visible */
     242       47232 :         CommandCounterIncrement();
     243             : 
     244             :         /* Store the query for the view */
     245       47232 :         StoreViewQuery(address.objectId, viewParse, replace);
     246             : 
     247       47232 :         return address;
     248             :     }
     249             : }
     250             : 
     251             : /*
     252             :  * Verify that tupledesc associated with proposed new view definition
     253             :  * matches tupledesc of old view.  This is basically a cut-down version
     254             :  * of equalTupleDescs(), with code added to generate specific complaints.
     255             :  * Also, we allow the new tupledesc to have more columns than the old.
     256             :  */
     257             : static void
     258         126 : checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc)
     259             : {
     260             :     int         i;
     261             : 
     262         126 :     if (newdesc->natts < olddesc->natts)
     263           4 :         ereport(ERROR,
     264             :                 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
     265             :                  errmsg("cannot drop columns from view")));
     266             : 
     267         304 :     for (i = 0; i < olddesc->natts; i++)
     268             :     {
     269         190 :         Form_pg_attribute newattr = TupleDescAttr(newdesc, i);
     270         190 :         Form_pg_attribute oldattr = TupleDescAttr(olddesc, i);
     271             : 
     272             :         /* XXX msg not right, but we don't support DROP COL on view anyway */
     273         190 :         if (newattr->attisdropped != oldattr->attisdropped)
     274           0 :             ereport(ERROR,
     275             :                     (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
     276             :                      errmsg("cannot drop columns from view")));
     277             : 
     278         190 :         if (strcmp(NameStr(newattr->attname), NameStr(oldattr->attname)) != 0)
     279           4 :             ereport(ERROR,
     280             :                     (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
     281             :                      errmsg("cannot change name of view column \"%s\" to \"%s\"",
     282             :                             NameStr(oldattr->attname),
     283             :                             NameStr(newattr->attname)),
     284             :                      errhint("Use ALTER VIEW ... RENAME COLUMN ... to change name of view column instead.")));
     285             :         /* XXX would it be safe to allow atttypmod to change?  Not sure */
     286         186 :         if (newattr->atttypid != oldattr->atttypid ||
     287         182 :             newattr->atttypmod != oldattr->atttypmod)
     288           4 :             ereport(ERROR,
     289             :                     (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
     290             :                      errmsg("cannot change data type of view column \"%s\" from %s to %s",
     291             :                             NameStr(oldattr->attname),
     292             :                             format_type_with_typemod(oldattr->atttypid,
     293             :                                                      oldattr->atttypmod),
     294             :                             format_type_with_typemod(newattr->atttypid,
     295             :                                                      newattr->atttypmod))));
     296             :         /* We can ignore the remaining attributes of an attribute... */
     297             :     }
     298             : 
     299             :     /*
     300             :      * We ignore the constraint fields.  The new view desc can't have any
     301             :      * constraints, and the only ones that could be on the old view are
     302             :      * defaults, which we are happy to leave in place.
     303             :      */
     304         114 : }
     305             : 
     306             : static void
     307       47520 : DefineViewRules(Oid viewOid, Query *viewParse, bool replace)
     308             : {
     309             :     /*
     310             :      * Set up the ON SELECT rule.  Since the query has already been through
     311             :      * parse analysis, we use DefineQueryRewrite() directly.
     312             :      */
     313       47520 :     DefineQueryRewrite(pstrdup(ViewSelectRuleName),
     314             :                        viewOid,
     315             :                        NULL,
     316             :                        CMD_SELECT,
     317             :                        true,
     318             :                        replace,
     319       47520 :                        list_make1(viewParse));
     320             : 
     321             :     /*
     322             :      * Someday: automatic ON INSERT, etc
     323             :      */
     324       47520 : }
     325             : 
     326             : /*---------------------------------------------------------------
     327             :  * UpdateRangeTableOfViewParse
     328             :  *
     329             :  * Update the range table of the given parsetree.
     330             :  * This update consists of adding two new entries IN THE BEGINNING
     331             :  * of the range table (otherwise the rule system will die a slow,
     332             :  * horrible and painful death, and we do not want that now, do we?)
     333             :  * one for the OLD relation and one for the NEW one (both of
     334             :  * them refer in fact to the "view" relation).
     335             :  *
     336             :  * Of course we must also increase the 'varnos' of all the Var nodes
     337             :  * by 2...
     338             :  *
     339             :  * These extra RT entries are not actually used in the query,
     340             :  * except for run-time locking and permission checking.
     341             :  *---------------------------------------------------------------
     342             :  */
     343             : static Query *
     344       47520 : UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
     345             : {
     346             :     Relation    viewRel;
     347             :     List       *new_rt;
     348             :     ParseNamespaceItem *nsitem;
     349             :     RangeTblEntry *rt_entry1,
     350             :                *rt_entry2;
     351             :     ParseState *pstate;
     352             : 
     353             :     /*
     354             :      * Make a copy of the given parsetree.  It's not so much that we don't
     355             :      * want to scribble on our input, it's that the parser has a bad habit of
     356             :      * outputting multiple links to the same subtree for constructs like
     357             :      * BETWEEN, and we mustn't have OffsetVarNodes increment the varno of a
     358             :      * Var node twice.  copyObject will expand any multiply-referenced subtree
     359             :      * into multiple copies.
     360             :      */
     361       47520 :     viewParse = copyObject(viewParse);
     362             : 
     363             :     /* Create a dummy ParseState for addRangeTableEntryForRelation */
     364       47520 :     pstate = make_parsestate(NULL);
     365             : 
     366             :     /* need to open the rel for addRangeTableEntryForRelation */
     367       47520 :     viewRel = relation_open(viewOid, AccessShareLock);
     368             : 
     369             :     /*
     370             :      * Create the 2 new range table entries and form the new range table...
     371             :      * OLD first, then NEW....
     372             :      */
     373       47520 :     nsitem = addRangeTableEntryForRelation(pstate, viewRel,
     374             :                                            AccessShareLock,
     375             :                                            makeAlias("old", NIL),
     376             :                                            false, false);
     377       47520 :     rt_entry1 = nsitem->p_rte;
     378       47520 :     nsitem = addRangeTableEntryForRelation(pstate, viewRel,
     379             :                                            AccessShareLock,
     380             :                                            makeAlias("new", NIL),
     381             :                                            false, false);
     382       47520 :     rt_entry2 = nsitem->p_rte;
     383             : 
     384             :     /* Must override addRangeTableEntry's default access-check flags */
     385       47520 :     rt_entry1->requiredPerms = 0;
     386       47520 :     rt_entry2->requiredPerms = 0;
     387             : 
     388       47520 :     new_rt = lcons(rt_entry1, lcons(rt_entry2, viewParse->rtable));
     389             : 
     390       47520 :     viewParse->rtable = new_rt;
     391             : 
     392             :     /*
     393             :      * Now offset all var nodes by 2, and jointree RT indexes too.
     394             :      */
     395       47520 :     OffsetVarNodes((Node *) viewParse, 2, 0);
     396             : 
     397       47520 :     relation_close(viewRel, AccessShareLock);
     398             : 
     399       47520 :     return viewParse;
     400             : }
     401             : 
     402             : /*
     403             :  * DefineView
     404             :  *      Execute a CREATE VIEW command.
     405             :  */
     406             : ObjectAddress
     407       47386 : DefineView(ViewStmt *stmt, const char *queryString,
     408             :            int stmt_location, int stmt_len)
     409             : {
     410             :     RawStmt    *rawstmt;
     411             :     Query      *viewParse;
     412             :     RangeVar   *view;
     413             :     ListCell   *cell;
     414             :     bool        check_option;
     415             :     ObjectAddress address;
     416             : 
     417             :     /*
     418             :      * Run parse analysis to convert the raw parse tree to a Query.  Note this
     419             :      * also acquires sufficient locks on the source table(s).
     420             :      *
     421             :      * Since parse analysis scribbles on its input, copy the raw parse tree;
     422             :      * this ensures we don't corrupt a prepared statement, for example.
     423             :      */
     424       47386 :     rawstmt = makeNode(RawStmt);
     425       47386 :     rawstmt->stmt = (Node *) copyObject(stmt->query);
     426       47386 :     rawstmt->stmt_location = stmt_location;
     427       47386 :     rawstmt->stmt_len = stmt_len;
     428             : 
     429       47386 :     viewParse = parse_analyze(rawstmt, queryString, NULL, 0, NULL);
     430             : 
     431             :     /*
     432             :      * The grammar should ensure that the result is a single SELECT Query.
     433             :      * However, it doesn't forbid SELECT INTO, so we have to check for that.
     434             :      */
     435       47378 :     if (!IsA(viewParse, Query))
     436           0 :         elog(ERROR, "unexpected parse analysis result");
     437       47378 :     if (viewParse->utilityStmt != NULL &&
     438           4 :         IsA(viewParse->utilityStmt, CreateTableAsStmt))
     439           4 :         ereport(ERROR,
     440             :                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
     441             :                  errmsg("views must not contain SELECT INTO")));
     442       47374 :     if (viewParse->commandType != CMD_SELECT)
     443           0 :         elog(ERROR, "unexpected parse analysis result");
     444             : 
     445             :     /*
     446             :      * Check for unsupported cases.  These tests are redundant with ones in
     447             :      * DefineQueryRewrite(), but that function will complain about a bogus ON
     448             :      * SELECT rule, and we'd rather the message complain about a view.
     449             :      */
     450       47374 :     if (viewParse->hasModifyingCTE)
     451           0 :         ereport(ERROR,
     452             :                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
     453             :                  errmsg("views must not contain data-modifying statements in WITH")));
     454             : 
     455             :     /*
     456             :      * If the user specified the WITH CHECK OPTION, add it to the list of
     457             :      * reloptions.
     458             :      */
     459       47374 :     if (stmt->withCheckOption == LOCAL_CHECK_OPTION)
     460          16 :         stmt->options = lappend(stmt->options,
     461          16 :                                 makeDefElem("check_option",
     462          16 :                                             (Node *) makeString("local"), -1));
     463       47358 :     else if (stmt->withCheckOption == CASCADED_CHECK_OPTION)
     464          64 :         stmt->options = lappend(stmt->options,
     465          64 :                                 makeDefElem("check_option",
     466          64 :                                             (Node *) makeString("cascaded"), -1));
     467             : 
     468             :     /*
     469             :      * Check that the view is auto-updatable if WITH CHECK OPTION was
     470             :      * specified.
     471             :      */
     472       47374 :     check_option = false;
     473             : 
     474       48274 :     foreach(cell, stmt->options)
     475             :     {
     476         900 :         DefElem    *defel = (DefElem *) lfirst(cell);
     477             : 
     478         900 :         if (strcmp(defel->defname, "check_option") == 0)
     479          82 :             check_option = true;
     480             :     }
     481             : 
     482             :     /*
     483             :      * If the check option is specified, look to see if the view is actually
     484             :      * auto-updatable or not.
     485             :      */
     486       47374 :     if (check_option)
     487             :     {
     488             :         const char *view_updatable_error =
     489          82 :         view_query_is_auto_updatable(viewParse, true);
     490             : 
     491          82 :         if (view_updatable_error)
     492           0 :             ereport(ERROR,
     493             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
     494             :                      errmsg("WITH CHECK OPTION is supported only on automatically updatable views"),
     495             :                      errhint("%s", _(view_updatable_error))));
     496             :     }
     497             : 
     498             :     /*
     499             :      * If a list of column names was given, run through and insert these into
     500             :      * the actual query tree. - thomas 2000-03-08
     501             :      */
     502       47374 :     if (stmt->aliases != NIL)
     503             :     {
     504          38 :         ListCell   *alist_item = list_head(stmt->aliases);
     505             :         ListCell   *targetList;
     506             : 
     507          54 :         foreach(targetList, viewParse->targetList)
     508             :         {
     509          54 :             TargetEntry *te = lfirst_node(TargetEntry, targetList);
     510             : 
     511             :             /* junk columns don't get aliases */
     512          54 :             if (te->resjunk)
     513           0 :                 continue;
     514          54 :             te->resname = pstrdup(strVal(lfirst(alist_item)));
     515          54 :             alist_item = lnext(stmt->aliases, alist_item);
     516          54 :             if (alist_item == NULL)
     517          38 :                 break;          /* done assigning aliases */
     518             :         }
     519             : 
     520          38 :         if (alist_item != NULL)
     521           0 :             ereport(ERROR,
     522             :                     (errcode(ERRCODE_SYNTAX_ERROR),
     523             :                      errmsg("CREATE VIEW specifies more column "
     524             :                             "names than columns")));
     525             :     }
     526             : 
     527             :     /* Unlogged views are not sensible. */
     528       47374 :     if (stmt->view->relpersistence == RELPERSISTENCE_UNLOGGED)
     529           0 :         ereport(ERROR,
     530             :                 (errcode(ERRCODE_SYNTAX_ERROR),
     531             :                  errmsg("views cannot be unlogged because they do not have storage")));
     532             : 
     533             :     /*
     534             :      * If the user didn't explicitly ask for a temporary view, check whether
     535             :      * we need one implicitly.  We allow TEMP to be inserted automatically as
     536             :      * long as the CREATE command is consistent with that --- no explicit
     537             :      * schema name.
     538             :      */
     539       47374 :     view = copyObject(stmt->view);   /* don't corrupt original command */
     540       47374 :     if (view->relpersistence == RELPERSISTENCE_PERMANENT
     541       47226 :         && isQueryUsingTempRelation(viewParse))
     542             :     {
     543          72 :         view->relpersistence = RELPERSISTENCE_TEMP;
     544          72 :         ereport(NOTICE,
     545             :                 (errmsg("view \"%s\" will be a temporary view",
     546             :                         view->relname)));
     547             :     }
     548             : 
     549             :     /*
     550             :      * Create the view relation
     551             :      *
     552             :      * NOTE: if it already exists and replace is false, the xact will be
     553             :      * aborted.
     554             :      */
     555       94748 :     address = DefineVirtualRelation(view, viewParse->targetList,
     556       47374 :                                     stmt->replace, stmt->options, viewParse);
     557             : 
     558       47346 :     return address;
     559             : }
     560             : 
     561             : /*
     562             :  * Use the rules system to store the query for the view.
     563             :  */
     564             : void
     565       47520 : StoreViewQuery(Oid viewOid, Query *viewParse, bool replace)
     566             : {
     567             :     /*
     568             :      * The range table of 'viewParse' does not contain entries for the "OLD"
     569             :      * and "NEW" relations. So... add them!
     570             :      */
     571       47520 :     viewParse = UpdateRangeTableOfViewParse(viewOid, viewParse);
     572             : 
     573             :     /*
     574             :      * Now create the rules associated with the view.
     575             :      */
     576       47520 :     DefineViewRules(viewOid, viewParse, replace);
     577       47520 : }

Generated by: LCOV version 1.13