Re: Weird CASE WHEN behaviour causing query to be suddenly very slow - Mailing list pgsql-performance

From David G. Johnston
Subject Re: Weird CASE WHEN behaviour causing query to be suddenly very slow
Date
Msg-id CAKFQuwYTKZT7CyWEn1qorQzcEh2=O-AaEQTKyH7QuD1s7v_Bhw@mail.gmail.com
Whole thread Raw
In response to Re: Weird CASE WHEN behaviour causing query to be suddenly very slow  ("Kevin Viraud" <kevin.viraud@rocket-internet.de>)
List pgsql-performance


On Tue, Mar 31, 2015 at 8:58 AM, Kevin Viraud <kevin.viraud@rocket-internet.de> wrote:
Touche ! Thanks a lot.

Looking more at the data yes it goes very often to ELSE Clause.  And
therefore reaching  the MAX_CACHED_RES.

In there anyway to increase that value  ?

Basically, I have several tables containing millions of rows and let say 5
columns. Those five columns, depending of their  combination give me a 6th
value.
We have complex patterns to match and using simple LIKE / EQUAL and so on
wouldn't be enough. This can be applied to N number of table so we
refactored this process into a function that we can use in the SELECT
statement, by giving only the 5 values each time.

I wouldn't mind using a table and mapping it through a join  if it were for
my own use.
But the final query has to be readable and usable for almost-non-initiated
SQL user... So using a function with encapsulated case when seemed to be a
good idea and so far worked nicely.

But we might consider changing it if we have no other choice...

Regards,

Kevin


​Thoughts...​


Rewrite the function in pl/perl​ and compare performance

​Hierarchy of CASE statements allowing you to reduce the number of possibilities in exchange for manually pre-processing the batches on a significantly less complicated condition probably using only 1 or 2 columns instead of all five.​

​I'm not familiar with the caching constraint or the data so its hard to make more specific suggestions.

David J.​

pgsql-performance by date:

Previous
From: "Kevin Viraud"
Date:
Subject: Re: Weird CASE WHEN behaviour causing query to be suddenly very slow
Next
From: Josh Berkus
Date:
Subject: Some performance testing?