~ubuntu-branches/ubuntu/trusty/postgresql-9.3/trusty-proposed

« back to all changes in this revision

Viewing changes to src/backend/catalog/namespace.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-07-24 16:13:59 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140724161359-uk325qfv03euxuuh
Tags: 9.3.5-0ubuntu0.14.04.1
* New upstream bug fix release: (LP: #1348176)
  - pg_upgrade: Users who upgraded to version 9.3 using pg_upgrade may have
    an issue with transaction information which causes VACUUM to eventually
    fail. These users should run the script provided in the release notes to
    determine if their installation is affected, and then take the remedy
    steps outlined there.
  - Various data integrity and other bug fixes.
  - Secure Unix-domain sockets of temporary postmasters started during make
    check.
    Any local user able to access the socket file could connect as the
    server's bootstrap superuser, then proceed to execute arbitrary code as
    the operating-system user running the test, as we previously noted in
    CVE-2014-0067. This change defends against that risk by placing the
    server's socket in a temporary, mode 0700 subdirectory of /tmp.
  - See release notes for details:
    http://www.postgresql.org/about/news/1534/
* Remove pg_regress patches to support --host=/path, obsolete with above
  upstream changes and not applicable any more.
* Drop tcl8.6 patch, applied upstream.
* Add missing logrotate test dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
 * when we are obeying an override search path spec that says not to use the
67
67
 * temp namespace, or the temp namespace is included in the explicit list.)
68
68
 *
69
 
 * 2. The system catalog namespace is always searched.  If the system
 
69
 * 2. The system catalog namespace is always searched.  If the system
70
70
 * namespace is present in the explicit path then it will be searched in
71
71
 * the specified order; otherwise it will be searched after TEMP tables and
72
 
 * *before* the explicit list.  (It might seem that the system namespace
 
72
 * *before* the explicit list.  (It might seem that the system namespace
73
73
 * should be implicitly last, but this behavior appears to be required by
74
74
 * SQL99.  Also, this provides a way to search the system namespace first
75
75
 * without thereby making it the default creation target namespace.)
87
87
 * to refer to the current backend's temp namespace.  This is usually also
88
88
 * ignorable if the temp namespace hasn't been set up, but there's a special
89
89
 * case: if "pg_temp" appears first then it should be the default creation
90
 
 * target.      We kluge this case a little bit so that the temp namespace isn't
 
90
 * target.  We kluge this case a little bit so that the temp namespace isn't
91
91
 * set up until the first attempt to create something in it.  (The reason for
92
92
 * klugery is that we can't create the temp namespace outside a transaction,
93
93
 * but initial GUC processing of search_path happens outside a transaction.)
98
98
 * In bootstrap mode, the search path is set equal to "pg_catalog", so that
99
99
 * the system namespace is the only one searched or inserted into.
100
100
 * initdb is also careful to set search_path to "pg_catalog" for its
101
 
 * post-bootstrap standalone backend runs.      Otherwise the default search
 
101
 * post-bootstrap standalone backend runs.  Otherwise the default search
102
102
 * path is determined by GUC.  The factory default path contains the PUBLIC
103
103
 * namespace (if it exists), preceded by the user's personal namespace
104
104
 * (if one exists).
162
162
/*
163
163
 * myTempNamespace is InvalidOid until and unless a TEMP namespace is set up
164
164
 * in a particular backend session (this happens when a CREATE TEMP TABLE
165
 
 * command is first executed).  Thereafter it's the OID of the temp namespace.
 
165
 * command is first executed).  Thereafter it's the OID of the temp namespace.
166
166
 *
167
167
 * myTempToastNamespace is the OID of the namespace for my temp tables' toast
168
 
 * tables.      It is set when myTempNamespace is, and is InvalidOid before that.
 
168
 * tables.  It is set when myTempNamespace is, and is InvalidOid before that.
169
169
 *
170
170
 * myTempNamespaceSubID shows whether we've created the TEMP namespace in the
171
 
 * current subtransaction.      The flag propagates up the subtransaction tree,
 
171
 * current subtransaction.  The flag propagates up the subtransaction tree,
172
172
 * so the main transaction will correctly recognize the flag if all
173
173
 * intermediate subtransactions commit.  When it is InvalidSubTransactionId,
174
174
 * we either haven't made the TEMP namespace yet, or have successfully
250
250
        }
251
251
 
252
252
        /*
253
 
         * DDL operations can change the results of a name lookup.      Since all such
 
253
         * DDL operations can change the results of a name lookup.  Since all such
254
254
         * operations will generate invalidation messages, we keep track of
255
255
         * whether any such messages show up while we're performing the operation,
256
256
         * and retry until either (1) no more invalidation messages show up or (2)
259
259
         * But if lockmode = NoLock, then we assume that either the caller is OK
260
260
         * with the answer changing under them, or that they already hold some
261
261
         * appropriate lock, and therefore return the first answer we get without
262
 
         * checking for invalidation messages.  Also, if the requested lock is
 
262
         * checking for invalidation messages.  Also, if the requested lock is
263
263
         * already held, no LockRelationOid will not AcceptInvalidationMessages,
264
264
         * so we may fail to notice a change.  We could protect against that case
265
265
         * by calling AcceptInvalidationMessages() before beginning this loop, but
396
396
                        break;
397
397
 
398
398
                /*
399
 
                 * Something may have changed.  Let's repeat the name lookup, to make
 
399
                 * Something may have changed.  Let's repeat the name lookup, to make
400
400
                 * sure this name still references the same relation it did
401
401
                 * previously.
402
402
                 */
869
869
 * and the returned nvargs will always be zero.
870
870
 *
871
871
 * If expand_defaults is true, functions that could match after insertion of
872
 
 * default argument values will also be retrieved.      In this case the returned
 
872
 * default argument values will also be retrieved.  In this case the returned
873
873
 * structs could have nargs > passed-in nargs, and ndargs is set to the number
874
874
 * of additional args (which can be retrieved from the function's
875
875
 * proargdefaults entry).
1025
1025
                         * Call uses positional notation
1026
1026
                         *
1027
1027
                         * Check if function is variadic, and get variadic element type if
1028
 
                         * so.  If expand_variadic is false, we should just ignore
 
1028
                         * so.  If expand_variadic is false, we should just ignore
1029
1029
                         * variadic-ness.
1030
1030
                         */
1031
1031
                        if (pronargs <= nargs && expand_variadic)
1155
1155
                        if (prevResult)
1156
1156
                        {
1157
1157
                                /*
1158
 
                                 * We have a match with a previous result.      Decide which one
 
1158
                                 * We have a match with a previous result.  Decide which one
1159
1159
                                 * to keep, or mark it ambiguous if we can't decide.  The
1160
1160
                                 * logic here is preference > 0 means prefer the old result,
1161
1161
                                 * preference < 0 means prefer the new, preference = 0 means
1540
1540
 * identical entries in later namespaces.
1541
1541
 *
1542
1542
 * The returned items always have two args[] entries --- one or the other
1543
 
 * will be InvalidOid for a prefix or postfix oprkind.  nargs is 2, too.
 
1543
 * will be InvalidOid for a prefix or postfix oprkind.  nargs is 2, too.
1544
1544
 */
1545
1545
FuncCandidateList
1546
1546
OpernameGetCandidates(List *names, char oprkind)
2521
2521
/*
2522
2522
 * TSConfigIsVisible
2523
2523
 *              Determine whether a text search configuration (identified by OID)
2524
 
 *              is visible in the current search path.  Visible means "would be found
 
2524
 *              is visible in the current search path.  Visible means "would be found
2525
2525
 *              by searching for the unqualified text search configuration name".
2526
2526
 */
2527
2527
bool
2840
2840
/*
2841
2841
 * get_namespace_oid - given a namespace name, look up the OID
2842
2842
 *
2843
 
 * If missing_ok is false, throw an error if namespace name not found.  If
 
2843
 * If missing_ok is false, throw an error if namespace name not found.  If
2844
2844
 * true, just return InvalidOid.
2845
2845
 */
2846
2846
Oid
3055
3055
 
3056
3056
/*
3057
3057
 * GetTempToastNamespace - get the OID of my temporary-toast-table namespace,
3058
 
 * which must already be assigned.      (This is only used when creating a toast
 
3058
 * which must already be assigned.  (This is only used when creating a toast
3059
3059
 * table for a temp table, so we must have already done InitTempTableNamespace)
3060
3060
 */
3061
3061
Oid
3153
3153
 *
3154
3154
 * It's possible that newpath->useTemp is set but there is no longer any
3155
3155
 * active temp namespace, if the path was saved during a transaction that
3156
 
 * created a temp namespace and was later rolled back.  In that case we just
3157
 
 * ignore useTemp.      A plausible alternative would be to create a new temp
 
3156
 * created a temp namespace and was later rolled back.  In that case we just
 
3157
 * ignore useTemp.  A plausible alternative would be to create a new temp
3158
3158
 * namespace, but for existing callers that's not necessary because an empty
3159
3159
 * temp namespace wouldn't affect their results anyway.
3160
3160
 *
3187
3187
                firstNS = linitial_oid(oidlist);
3188
3188
 
3189
3189
        /*
3190
 
         * Add any implicitly-searched namespaces to the list.  Note these go on
 
3190
         * Add any implicitly-searched namespaces to the list.  Note these go on
3191
3191
         * the front, not the back; also notice that we do not check USAGE
3192
3192
         * permissions for these.
3193
3193
         */
3510
3510
        }
3511
3511
 
3512
3512
        /*
3513
 
         * Remember the first member of the explicit list.      (Note: this is
 
3513
         * Remember the first member of the explicit list.  (Note: this is
3514
3514
         * nominally wrong if temp_missing, but we need it anyway to distinguish
3515
3515
         * explicit from implicit mention of pg_catalog.)
3516
3516
         */
3520
3520
                firstNS = linitial_oid(oidlist);
3521
3521
 
3522
3522
        /*
3523
 
         * Add any implicitly-searched namespaces to the list.  Note these go on
 
3523
         * Add any implicitly-searched namespaces to the list.  Note these go on
3524
3524
         * the front, not the back; also notice that we do not check USAGE
3525
3525
         * permissions for these.
3526
3526
         */
3575
3575
 
3576
3576
        /*
3577
3577
         * First, do permission check to see if we are authorized to make temp
3578
 
         * tables.      We use a nonstandard error message here since "databasename:
 
3578
         * tables.  We use a nonstandard error message here since "databasename:
3579
3579
         * permission denied" might be a tad cryptic.
3580
3580
         *
3581
3581
         * Note that ACL_CREATE_TEMP rights are rechecked in pg_namespace_aclmask;
3594
3594
         * Do not allow a Hot Standby slave session to make temp tables.  Aside
3595
3595
         * from problems with modifying the system catalogs, there is a naming
3596
3596
         * conflict: pg_temp_N belongs to the session with BackendId N on the
3597
 
         * master, not to a slave session with the same BackendId.      We should not
 
3597
         * master, not to a slave session with the same BackendId.  We should not
3598
3598
         * be able to get here anyway due to XactReadOnly checks, but let's just
3599
 
         * make real sure.      Note that this also backstops various operations that
 
3599
         * make real sure.  Note that this also backstops various operations that
3600
3600
         * allow XactReadOnly transactions to modify temp tables; they'd need
3601
3601
         * RecoveryInProgress checks if not for this.
3602
3602
         */
3952
3952
        /*
3953
3953
         * If the temp namespace should be first, force it to exist.  This is so
3954
3954
         * that callers can trust the result to reflect the actual default
3955
 
         * creation namespace.  It's a bit bogus to do this here, since
 
3955
         * creation namespace.  It's a bit bogus to do this here, since
3956
3956
         * current_schema() is supposedly a stable function without side-effects,
3957
3957
         * but the alternatives seem worse.
3958
3958
         */
3974
3974
 
3975
3975
/*
3976
3976
 * Fetch the active search path into a caller-allocated array of OIDs.
3977
 
 * Returns the number of path entries.  (If this is more than sarray_len,
 
3977
 * Returns the number of path entries.  (If this is more than sarray_len,
3978
3978
 * then the data didn't fit and is not all stored.)
3979
3979
 *
3980
3980
 * The returned list always includes the implicitly-prepended namespaces,