~ubuntu-branches/ubuntu/quantal/postgresql-9.1/quantal-updates

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/ruleutils.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-06-04 06:47:45 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20120604064745-dvs00jnur0vgkwqs
Tags: 9.1.4-1
* Urgency medium due to security fixes.
* New upstream bug fix/security release:
  - Fix incorrect password transformation in "contrib/pgcrypto"'s DES
    crypt() function.
    If a password string contained the byte value 0x80, the remainder
    of the password was ignored, causing the password to be much weaker
    than it appeared. With this fix, the rest of the string is properly
    included in the DES hash. Any stored password values that are
    affected by this bug will thus no longer match, so the stored
    values may need to be updated. (CVE-2012-2143)
  - Ignore SECURITY DEFINER and SET attributes for a procedural
    language's call handler. Applying such attributes to a call handler
    could crash the server. (CVE-2012-2655)
  - Make "contrib/citext"'s upgrade script fix collations of citext
    arrays and domains over citext.
    Release 9.1.2 provided a fix for collations of citext columns and
    indexes in databases upgraded or reloaded from pre-9.1
    installations, but that fix was incomplete: it neglected to handle
    arrays and domains over citext. This release extends the module's
    upgrade script to handle these cases. As before, if you have
    already run the upgrade script, you'll need to run the collation
    update commands by hand instead. See the 9.1.2 release notes for
    more information about doing this.
  - Allow numeric timezone offsets in timestamp input to be up to 16
    hours away from UTC. Some historical time zones have offsets larger than
    15 hours, the previous limit. This could result in dumped data values
    being rejected during reload.
  - Fix timestamp conversion to cope when the given time is exactly the
    last DST transition time for the current timezone.
    This oversight has been there a long time, but was not noticed
    previously because most DST-using zones are presumed to have an
    indefinite sequence of future DST transitions.
  - Fix text to name and char to name casts to perform string
    truncation correctly in multibyte encodings.
  - Fix memory copying bug in to_tsquery().
  - Ensure txid_current() reports the correct epoch when executed in
    hot standby.
  - Fix planner's handling of outer PlaceHolderVars within subqueries.
    This bug concerns sub-SELECTs that reference variables coming from
    the nullable side of an outer join of the surrounding query. In
    9.1, queries affected by this bug would fail with "ERROR:
    Upper-level PlaceHolderVar found where not expected". But in 9.0
    and 8.4, you'd silently get possibly-wrong answers, since the value
    transmitted into the subquery wouldn't go to null when it should.
  - Fix planning of UNION ALL subqueries with output columns that are
    not simple variables.
    Planning of such cases got noticeably worse in 9.1 as a result of a
    misguided fix for "MergeAppend child's targetlist doesn't match
    MergeAppend" errors. Revert that fix and do it another way.
  - Fix slow session startup when pg_attribute is very large.
    If pg_attribute exceeds one-fourth of shared_buffers, cache
    rebuilding code that is sometimes needed during session start would
    trigger the synchronized-scan logic, causing it to take many times
    longer than normal. The problem was particularly acute if many new
    sessions were starting at once.
  - Ensure sequential scans check for query cancel reasonably often.
    A scan encountering many consecutive pages that contain no live
    tuples would not respond to interrupts meanwhile.
  - Ensure the Windows implementation of PGSemaphoreLock() clears
    ImmediateInterruptOK before returning.
    This oversight meant that a query-cancel interrupt received later
    in the same query could be accepted at an unsafe time, with
    unpredictable but not good consequences.
  - Show whole-row variables safely when printing views or rules.
    Corner cases involving ambiguous names (that is, the name could be
    either a table or column name of the query) were printed in an
    ambiguous way, risking that the view or rule would be interpreted
    differently after dump and reload. Avoid the ambiguous case by
    attaching a no-op cast.
  - Fix "COPY FROM" to properly handle null marker strings that
    correspond to invalid encoding.
    A null marker string such as E'\\0' should work, and did work in
    the past, but the case got broken in 8.4.
  - Fix "EXPLAIN VERBOSE" for writable CTEs containing RETURNING
    clauses.
  - Fix "PREPARE TRANSACTION" to work correctly in the presence of
    advisory locks.
    Historically, "PREPARE TRANSACTION" has simply ignored any
    session-level advisory locks the session holds, but this case was
    accidentally broken in 9.1.
  - Fix truncation of unlogged tables.
  - Ignore missing schemas during non-interactive assignments of
    search_path.
    This re-aligns 9.1's behavior with that of older branches.
    Previously 9.1 would throw an error for nonexistent schemas
    mentioned in search_path settings obtained from places such as
    "ALTER DATABASE SET".
  - Fix bugs with temporary or transient tables used in extension
    scripts.
    This includes cases such as a rewriting "ALTER TABLE" within an
    extension update script, since that uses a transient table behind
    the scenes.
  - Ensure autovacuum worker processes perform stack depth checking
    properly.
    Previously, infinite recursion in a function invoked by
    auto-"ANALYZE" could crash worker processes.
  - Fix logging collector to not lose log coherency under high load.
    The collector previously could fail to reassemble large messages if
    it got too busy.
  - Fix logging collector to ensure it will restart file rotation after
    receiving SIGHUP.
  - Fix "too many LWLocks taken" failure in GiST indexes.
  - Fix WAL replay logic for GIN indexes to not fail if the index was
    subsequently dropped.
  - Correctly detect SSI conflicts of prepared transactions after a
    crash.
  - Avoid synchronous replication delay when committing a transaction
    that only modified temporary tables.
    In such a case the transaction's commit record need not be flushed
    to standby servers, but some of the code didn't know that and
    waited for it to happen anyway.
  - Fix error handling in pg_basebackup.
  - Fix walsender to not go into a busy loop if connection is
    terminated.
  - Fix memory leak in PL/pgSQL's "RETURN NEXT" command.
  - Fix PL/pgSQL's "GET DIAGNOSTICS" command when the target is the
    function's first variable.
  - Ensure that PL/Perl package-qualifies the _TD variable.
    This bug caused trigger invocations to fail when they are nested
    within a function invocation that changes the current package.
  - Fix PL/Python functions returning composite types to accept a
    string for their result value.
    This case was accidentally broken by the 9.1 additions to allow a
    composite result value to be supplied in other formats, such as
    dictionaries.
  - Fix potential access off the end of memory in psql's expanded
    display ("\x") mode.
  - Fix several performance problems in pg_dump when the database
    contains many objects.
    pg_dump could get very slow if the database contained many schemas,
    or if many objects are in dependency loops, or if there are many
    owned sequences.
  - Fix memory and file descriptor leaks in pg_restore when reading a
    directory-format archive.
  - Fix pg_upgrade for the case that a database stored in a non-default
    tablespace contains a table in the cluster's default tablespace.
  - In ecpg, fix rare memory leaks and possible overwrite of one byte
    after the sqlca_t structure.
  - Fix "contrib/dblink"'s dblink_exec() to not leak temporary database
    connections upon error.
  - Fix "contrib/dblink" to report the correct connection name in error
    messages.
  - Fix "contrib/vacuumlo" to use multiple transactions when dropping
    many large objects.
    This change avoids exceeding max_locks_per_transaction when many
    objects need to be dropped. The behavior can be adjusted with the
    new -l (limit) option.
* debian/control: Bump debhelper build dependency to >= 8, as it does not
  build with earlier versions.
* debian/control: Move bzr branches to alioth, so that other members of
  pkg-postgresql can commit. Update Vcs-* tags.
* debian/control: Set Maintainer: to pkg-postgresql group, and move myself
  to Uploaders:.

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
static void get_rule_windowclause(Query *query, deparse_context *context);
204
204
static void get_rule_windowspec(WindowClause *wc, List *targetList,
205
205
                                        deparse_context *context);
206
 
static char *get_variable(Var *var, int levelsup, bool showstar,
 
206
static char *get_variable(Var *var, int levelsup, bool istoplevel,
207
207
                         deparse_context *context);
208
208
static RangeTblEntry *find_rte_by_refname(const char *refname,
209
209
                                        deparse_context *context);
3013
3013
                 * "foo.*", which is the preferred notation in most contexts, but at
3014
3014
                 * the top level of a SELECT list it's not right (the parser will
3015
3015
                 * expand that notation into multiple columns, yielding behavior
3016
 
                 * different from a whole-row Var).  We want just "foo", instead.
 
3016
                 * different from a whole-row Var).  We need to call get_variable
 
3017
                 * directly so that we can tell it to do the right thing.
3017
3018
                 */
3018
3019
                if (tle->expr && IsA(tle->expr, Var))
3019
3020
                {
3020
 
                        attname = get_variable((Var *) tle->expr, 0, false, context);
 
3021
                        attname = get_variable((Var *) tle->expr, 0, true, context);
3021
3022
                }
3022
3023
                else
3023
3024
                {
3684
3685
 * the Var's varlevelsup has to be interpreted with respect to a context
3685
3686
 * above the current one; levelsup indicates the offset.
3686
3687
 *
3687
 
 * If showstar is TRUE, whole-row Vars are displayed as "foo.*";
3688
 
 * if FALSE, merely as "foo".
 
3688
 * If istoplevel is TRUE, the Var is at the top level of a SELECT's
 
3689
 * targetlist, which means we need special treatment of whole-row Vars.
 
3690
 * Instead of the normal "tab.*", we'll print "tab.*::typename", which is a
 
3691
 * dirty hack to prevent "tab.*" from being expanded into multiple columns.
 
3692
 * (The parser will strip the useless coercion, so no inefficiency is added in
 
3693
 * dump and reload.)  We used to print just "tab" in such cases, but that is
 
3694
 * ambiguous and will yield the wrong result if "tab" is also a plain column
 
3695
 * name in the query.
3689
3696
 *
3690
 
 * Returns the attname of the Var, or NULL if not determinable.
 
3697
 * Returns the attname of the Var, or NULL if the Var has no attname (because
 
3698
 * it is a whole-row Var).
3691
3699
 */
3692
3700
static char *
3693
 
get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
 
3701
get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context)
3694
3702
{
3695
3703
        StringInfo      buf = context->buf;
3696
3704
        RangeTblEntry *rte;
3857
3865
                                if (IsA(aliasvar, Var))
3858
3866
                                {
3859
3867
                                        return get_variable(aliasvar, var->varlevelsup + levelsup,
3860
 
                                                                                showstar, context);
 
3868
                                                                                istoplevel, context);
3861
3869
                                }
3862
3870
                        }
3863
 
                        /* Unnamed join has neither schemaname nor refname */
 
3871
 
 
3872
                        /*
 
3873
                         * Unnamed join has neither schemaname nor refname.  (Note: since
 
3874
                         * it's unnamed, there is no way the user could have referenced it
 
3875
                         * to create a whole-row Var for it.  So we don't have to cover
 
3876
                         * that case below.)
 
3877
                         */
3864
3878
                        refname = NULL;
3865
3879
                }
3866
3880
        }
3876
3890
                        appendStringInfo(buf, "%s.",
3877
3891
                                                         quote_identifier(schemaname));
3878
3892
                appendStringInfoString(buf, quote_identifier(refname));
3879
 
                if (attname || showstar)
3880
 
                        appendStringInfoChar(buf, '.');
 
3893
                appendStringInfoChar(buf, '.');
3881
3894
        }
3882
3895
        if (attname)
3883
3896
                appendStringInfoString(buf, quote_identifier(attname));
3884
 
        else if (showstar)
 
3897
        else
 
3898
        {
3885
3899
                appendStringInfoChar(buf, '*');
 
3900
                if (istoplevel)
 
3901
                        appendStringInfo(buf, "::%s",
 
3902
                                                         format_type_with_typemod(var->vartype,
 
3903
                                                                                                          var->vartypmod));
 
3904
        }
3886
3905
 
3887
3906
        return attname;
3888
3907
}
4819
4838
        switch (nodeTag(node))
4820
4839
        {
4821
4840
                case T_Var:
4822
 
                        (void) get_variable((Var *) node, 0, true, context);
 
4841
                        (void) get_variable((Var *) node, 0, false, context);
4823
4842
                        break;
4824
4843
 
4825
4844
                case T_Const: