Re: [HACKERS] WIP Patch: Precalculate stable functions, infrastructure v1

From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Marina Polyakova <m(dot)polyakova(at)postgrespro(dot)ru>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>, Andres Freund <andres(at)anarazel(dot)de>, Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [HACKERS] WIP Patch: Precalculate stable functions, infrastructure v1
Date: 2017-12-31 11:55:47
Message-ID: CA+q6zcX+0q_32J_VLjQ_jwr-MqNLmJZXAbCE+eKrsnhd8Dng5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 31 December 2017 at 06:55, Marina Polyakova <m(dot)polyakova(at)postgrespro(dot)ru>
wrote:
>
> Secondly, here there's a sixth version of the patch for the
precalculation of
> stable or immutable functions, stable or immutable operators and other
> nonvolatile expressions.

Thanks for your patch, looks quite interesting!

> To not send big patch I have split it (that's why version starts with the
> first again) and here I send infrastructure patch which includes:

Yeah, but it's still 18k lines :) After the first quick glance I have a few
small questions.

If I call a stable function from a query and subquery, looks like it's
cached:

```
=# select stable_with_int(1) from (select stable_with_int(1) from x) q;
NOTICE: 00000: stable with int
LOCATION: exec_stmt_raise, pl_exec.c:3353
stable_with_int
-----------------
1
1
1
1
(4 rows)
```

But the same from CTE works different, is it supposed to be like that?

```
=# with data as (select stable_with_int(1) from x) select
stable_with_int(1) from data;
NOTICE: 00000: stable with int
LOCATION: exec_stmt_raise, pl_exec.c:3353
NOTICE: 00000: stable with int
LOCATION: exec_stmt_raise, pl_exec.c:3353
stable_with_int
-----------------
1
1
1
1
(4 rows)
```

Also I see this pattern quite some time, maybe it makes sense to move it to
a function?

```
+ /* create and return CachedExpr */
+ CachedExpr *new_node = makeNode(CachedExpr);
+ new_node->subexpr = (CacheableExpr *) current_node;
+
+ context->root->hasCachedExpr = true;
+
+ return (Node *) new_node;
```

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2017-12-31 12:01:55 Re: MCV lists for highly skewed distributions
Previous Message Vik Fearing 2017-12-31 11:34:17 Sample values for pg_stat_statements