Re: [RFC] [PATCH] Flexible "partition pruning" hook

Поиск
Список
Период
Сортировка
От Kyotaro Horiguchi
Тема Re: [RFC] [PATCH] Flexible "partition pruning" hook
Дата
Msg-id 20190712.150527.145133646.horikyota.ntt@gmail.com
обсуждение исходный текст
Ответ на Re: [RFC] [PATCH] Flexible "partition pruning" hook  (Mike Palmiotto <mike.palmiotto@crunchydata.com>)
Ответы Re: [RFC] [PATCH] Flexible "partition pruning" hook  (Amit Langote <amitlangote09@gmail.com>)
Список pgsql-hackers
Hello.

I'm on Peter's side. Unlike other similar hooks, this hook is
provided just to introduce arbitrary inconsistency in partition
pruning.

# By the way, InvokePartitionPruningHook seems useless if the
# reason for it is to avoid duplicate if()'s . 

Adding check constraint on children works as far as the RLSish
function is immutable. Do you have any concrete example or
picture of what you want to achieve?


By the way, while considering this, I noticed the following table
definition passes.

> create table t (id serial, a text check (a = '' or a = CURRENT_USER::text));

I don't think it is the right behavior.

> grant all on t to public;
> grant all on t_id_seq to public;
> \c postgres u1
> insert into t(a) values ('u1');
> \c postgres u2
> insert into t(a) values ('u2');
> \c postgres horiguti
> insert into t(a) values ('horiguti');

> select * from t;
>  id |    a     
> ----+----------
>   1 | u1
>   2 | u2
>   3 | horiguti

Broken... The attached patch make parser reject that but I'm not
sure how much it affects existing users.

> =# create table t (id serial, a text check (a = '' or a = CURRENT_USER::text));
> ERROR:  mutable functions are not allowed in constraint expression

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 97f535a2f0..2fd233bf18 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -2376,6 +2376,15 @@ transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
 static Node *
 transformSQLValueFunction(ParseState *pstate, SQLValueFunction *svf)
 {
+    /*
+     * All SQL value functions are stable so we reject them in check
+     * constraint expressions.
+     */
+    if (pstate->p_expr_kind == EXPR_KIND_CHECK_CONSTRAINT)
+        ereport(ERROR,
+                (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+                 errmsg("mutable functions are not allowed in check constraints")));
+
     /*
      * All we need to do is insert the correct result type and (where needed)
      * validate the typmod, so we just modify the node in-place.
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index 2a44b434a5..6ea2f0326d 100644
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -271,6 +271,13 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
                                &nvargs, &vatype,
                                &declared_arg_types, &argdefaults);
 
+    /* mutable functions are not allowed in constraint expressions */
+    if (pstate->p_expr_kind == EXPR_KIND_CHECK_CONSTRAINT &&
+        func_volatile(funcid) != PROVOLATILE_IMMUTABLE)
+        ereport(ERROR,
+                (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+                 errmsg("mutable functions are not allowed in constraint expression")));
+
     cancel_parser_errposition_callback(&pcbstate);
 
     /*

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: Add parallelism and glibc dependent only options to reindexdb
Следующее
От: Shawn Debnath
Дата:
Сообщение: Re: Introduce timeout capability for ConditionVariableSleep