Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YI7UV-0000x9-LH for pgsql-performance@arkaria.postgresql.org; Mon, 02 Feb 2015 03:15:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YI7UU-0004lE-3s for pgsql-performance@arkaria.postgresql.org; Mon, 02 Feb 2015 03:15:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YI7UT-0004l7-0J for pgsql-performance@postgresql.org; Mon, 02 Feb 2015 03:15:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YI7UK-0004ho-HA for pgsql-performance@postgresql.org; Mon, 02 Feb 2015 03:15:55 +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 t123Fj3o012831; Sun, 1 Feb 2015 22:15:45 -0500 From: Tom Lane To: AlexK987 cc: pgsql-performance@postgresql.org Subject: Re: Why is GIN index slowing down my query? In-reply-to: <1422841046401-5836323.post@n5.nabble.com> References: <1422829941197-5836319.post@n5.nabble.com> <6888.1422833653@sss.pgh.pa.us> <1422841046401-5836323.post@n5.nabble.com> Comments: In-reply-to AlexK987 message dated "Sun, 01 Feb 2015 18:37:26 -0700" Date: Sun, 01 Feb 2015 22:15:45 -0500 Message-ID: <12830.1422846945@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 AlexK987 writes: > This is a realistic case: everyone have Python and Java skills, but PostGis > and Haskell and Closure are rare. If we are looking for a person that has > all the skills required for a task (array[1, 15]), that is "skills <@ > array[1, 15] " and not the opposite, right? One of us has this backwards. It might be me, but I don't think so. Consider a person who has the two desired skills plus skill #42: regression=# select array[1,15,42] <@ array[1,15]; ?column? ---------- f (1 row) regression=# select array[1,15,42] @> array[1,15]; ?column? ---------- t (1 row) > Also can you explain why " entries for "0" and "1" swamp everything else so > that the planner > doesn't know that eg "15" is really rare. " I thought that if a value is not > found in the histogram, than clearly that value is rare, correct? What am I > missing here? The problem is *how* rare. The planner will take the lowest frequency seen among the most common elements as an upper bound for the frequency of unlisted elements --- but if all you have in the stats array is 0 and 1, and they both have frequency 1.0, that doesn't tell you anything. And that's what I see for this example: regression=# select most_common_elems,most_common_elem_freqs from pg_stats where tablename = 'talent' and attname = 'skills'; most_common_elems | most_common_elem_freqs -------------------+------------------------ {0,1} | {1,1,1,1,0} (1 row) With a less skewed distribution, that rule of thumb would work better :-( 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