Re: Optimze usage of immutable functions as relation

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Aleksandr Parfenov <a(dot)parfenov(at)postgrespro(dot)ru>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Optimze usage of immutable functions as relation
Date: 2018-05-04 07:37:31
Message-ID: 87zi1g6jbj.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Aleksandr" == Aleksandr Parfenov <a(dot)parfenov(at)postgrespro(dot)ru> writes:

Aleksandr> The idea of the fix for this situation is to check is a
Aleksandr> result of the function constant or not during the planning
Aleksandr> of the query. Attached patch does this by processing Var
Aleksandr> entries at planner stage and replace them with constant
Aleksandr> value if it is possible. Plans after applying a patch
Aleksandr> (SeqScan query for comparison):

From an implementation point of view your patch is obviously broken in
many ways (starting with not checking varattno anywhere, and not
actually checking anywhere if the expression is volatile).

But more importantly the plans that you showed seem _worse_ in that
you've created extra calls to to_tsquery even though the query has been
written to try and avoid that.

I think you need to take a step back and explain more precisely what you
think you're trying to do and what the benefit (and cost) is.

Specific coding style points (not exhaustive):

Aleksandr> pointedNode->functions->length == 1

list_length()

Aleksandr> pointedNode->functions->head->data.ptr_value

linitial() or linitial_node()

Aleksandr> if (result->type == T_FuncExpr)

IsA()

(what if the result is the inline expansion of a volatile function?)

Aleksandr> pfree(result);

result is a whole tree of nodes, pfree is pointless here

(don't bother trying to fix the above points in this patch, that won't
address the fundamental flaws)

--
Andrew (irc:RhodiumToad)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Teodor Sigaev 2018-05-04 08:30:57 Re: [HACKERS] GSoC 2017: weekly progress reports (week 6)
Previous Message Heikki Linnakangas 2018-05-04 07:05:41 Re: [HACKERS] [BUGS] Bug in Physical Replication Slots (at least 9.5)?