~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/backend/commands/indexcmds.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-01-03 08:57:10 UTC
  • mfrom: (5.3.10 sid)
  • Revision ID: james.westby@ubuntu.com-20110103085710-v9u121v7u7oq8qca
Tags: 8.4.6-1~hardy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 *
10
10
 * IDENTIFICATION
11
 
 *        $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.185 2009/06/11 14:48:55 momjian Exp $
 
11
 *        $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.185.2.1 2010/05/27 15:59:15 tgl Exp $
12
12
 *
13
13
 *-------------------------------------------------------------------------
14
14
 */
34
34
#include "miscadmin.h"
35
35
#include "nodes/nodeFuncs.h"
36
36
#include "optimizer/clauses.h"
 
37
#include "optimizer/planner.h"
37
38
#include "parser/parse_coerce.h"
38
39
#include "parser/parse_func.h"
39
40
#include "parser/parsetree.h"
748
749
 
749
750
 
750
751
/*
 
752
 * CheckMutability
 
753
 *              Test whether given expression is mutable
 
754
 */
 
755
static bool
 
756
CheckMutability(Expr *expr)
 
757
{
 
758
        /*
 
759
         * First run the expression through the planner.  This has a couple of
 
760
         * important consequences.  First, function default arguments will get
 
761
         * inserted, which may affect volatility (consider "default now()").
 
762
         * Second, inline-able functions will get inlined, which may allow us to
 
763
         * conclude that the function is really less volatile than it's marked.
 
764
         * As an example, polymorphic functions must be marked with the most
 
765
         * volatile behavior that they have for any input type, but once we
 
766
         * inline the function we may be able to conclude that it's not so
 
767
         * volatile for the particular input type we're dealing with.
 
768
         *
 
769
         * We assume here that expression_planner() won't scribble on its input.
 
770
         */
 
771
        expr = expression_planner(expr);
 
772
 
 
773
        /* Now we can search for non-immutable functions */
 
774
        return contain_mutable_functions((Node *) expr);
 
775
}
 
776
 
 
777
 
 
778
/*
751
779
 * CheckPredicate
752
780
 *              Checks that the given partial-index predicate is valid.
753
781
 *
778
806
         * A predicate using mutable functions is probably wrong, for the same
779
807
         * reasons that we don't allow an index expression to use one.
780
808
         */
781
 
        if (contain_mutable_functions((Node *) predicate))
 
809
        if (CheckMutability(predicate))
782
810
                ereport(ERROR,
783
811
                                (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
784
812
                   errmsg("functions in index predicate must be marked IMMUTABLE")));
877
905
                         * if you aren't going to get the same result for the same data
878
906
                         * every time, it's not clear what the index entries mean at all.
879
907
                         */
880
 
                        if (contain_mutable_functions(attribute->expr))
 
908
                        if (CheckMutability((Expr *) attribute->expr))
881
909
                                ereport(ERROR,
882
910
                                                (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
883
911
                                                 errmsg("functions in index expression must be marked IMMUTABLE")));