pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kevin Viraud <kevin.viraud@rocket-internet.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Weird CASE WHEN behaviour causing query to be suddenly very slow
Date: Tue, 31 Mar 2015 09:58:30 -0400
Message-ID: <16234.1427810310@sss.pgh.pa.us> (raw)
In-Reply-To: <00a001d06b90$2d1bbe80$87533b80$@rocket-internet.de>
References: <00a001d06b90$2d1bbe80$87533b80$@rocket-internet.de>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

"Kevin Viraud" <kevin.viraud@rocket-internet.de> writes:
> I have an issue with a rather large CASE WHEN and I cannot figure out why
> it is so slow...

Do all the arms of the CASE usually fail, leaving you at the ELSE?

I suspect what's happening is that you're running into the MAX_CACHED_RES
limit in src/backend/utils/adt/regexp.c, so that instead of just compiling
each regexp once and then re-using 'em, the regexps are constantly falling
out of cache and then having to be recompiled.  They'd have to be used in
a nearly perfect round robin in order for the behavior to have such a big
cliff as you describe, though.  In this CASE structure, that suggests that
you're nearly always testing every regexp because they're all failing.

I have to think there's probably a better way to do whatever you're trying
to do, but there's not enough info here about your underlying goal to
suggest a better approach.  At the very least, if you need a many-armed
CASE, it behooves you to make sure the common cases appear early.

			regards, tom lane


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (9+ messages)  latest in thread

Message-ID: <16234.1427810310@sss.pgh.pa.us>
Permalink:  ../16234.1427810310@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16234.1427810310@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, kevin.viraud@rocket-internet.de
  Subject: Re: Weird CASE WHEN behaviour causing query to be suddenly very slow
  In-Reply-To: <16234.1427810310@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox