Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ycwgf-0005Tj-0u for pgsql-performance@arkaria.postgresql.org; Tue, 31 Mar 2015 13:58:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Ycwge-0006MH-0G for pgsql-performance@arkaria.postgresql.org; Tue, 31 Mar 2015 13:58:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Ycwgd-0006Lc-06 for pgsql-performance@postgresql.org; Tue, 31 Mar 2015 13:58:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YcwgZ-0005mt-S0 for pgsql-performance@postgresql.org; Tue, 31 Mar 2015 13:58:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t2VDwUGd016235; Tue, 31 Mar 2015 09:58:30 -0400 From: Tom Lane To: "Kevin Viraud" cc: pgsql-performance@postgresql.org Subject: Re: Weird CASE WHEN behaviour causing query to be suddenly very slow In-reply-to: <00a001d06b90$2d1bbe80$87533b80$@rocket-internet.de> References: <00a001d06b90$2d1bbe80$87533b80$@rocket-internet.de> Comments: In-reply-to "Kevin Viraud" message dated "Tue, 31 Mar 2015 10:53:35 +0200" Date: Tue, 31 Mar 2015 09:58:30 -0400 Message-ID: <16234.1427810310@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org "Kevin Viraud" 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