Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id D0BA46856E5 for ; Sun, 28 Feb 2010 23:16:23 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 63225-01-4 for ; Mon, 1 Mar 2010 03:16:12 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f187.google.com (mail-pz0-f187.google.com [209.85.222.187]) by mail.postgresql.org (Postfix) with ESMTP id 57B336413E4 for ; Sun, 28 Feb 2010 22:38:16 -0400 (AST) Received: by pzk17 with SMTP id 17so1497645pzk.31 for ; Sun, 28 Feb 2010 18:38:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=j5QsK7J0lbnH/L+N55KecXJNr9KwehKSuXqzTCzOFg4=; b=PlYCOwvb0PVp2hLB7ceF/dkle/eOLdM4T3DGI374VVWFgbT/NKqgGOlkaVT0eC1V4A fZmPRIsxmGo8GjzNC3qh60UV0ICemwWxAJpBkTx6kCaOU5ba9nC9sqDk/xnwoOwN7nwD yklcDtPhJ6988w09gj4H+kX29QzQc6DVNraKQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=gWfwHt4yNbOG5OX4NDzvNRdeA9JH1FhCnWeO162S9cKHP3KSHu8Hy5hwewG1h7S1Xa 6mT05g51GLOZ5Z5qQLb4zSwaJ+Ly0phl4F0++Jtcah1gWZvue1uDrs2i1m/4yMThIPT4 mN0o0vk+qG35r6zQ8uf0FDghvDPwz/9ZluUL0= Received: by 10.141.13.3 with SMTP id q3mr2103454rvi.204.1267411094345; Sun, 28 Feb 2010 18:38:14 -0800 (PST) Received: from ?192.168.2.65? (office.squiz.net [203.206.128.174]) by mx.google.com with ESMTPS id 22sm3211794pzk.1.2010.02.28.18.38.11 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 28 Feb 2010 18:38:13 -0800 (PST) Message-ID: <4B8B2890.40000@gmail.com> Date: Mon, 01 Mar 2010 13:38:08 +1100 From: Chris User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Josh Berkus CC: xu fei , postgres performance list Subject: Re: [HACKERS] full text search index scan query plan changed in 8.4.2? References: <60218.64374.qm@web45406.mail.sp1.yahoo.com> <4B8AF12A.4000002@agliodbs.com> In-Reply-To: <4B8AF12A.4000002@agliodbs.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/404 X-Sequence-Number: 37825 Josh Berkus wrote: > Xufei, > > List changed to psql-performance, which is where this discussion belongs. > >> I am testing the index used by full text search recently. >> >> I have install 8.3.9 and 8.4.2 separately. >> >> In 8.3.9, the query plan is like: >> >> postgres=# explain SELECT s.name as source , t.name as target FROM element as s, element as t WHERE to_tsvector('testcfg',s.name) @@ to_tsquery('testcfg',replace(t.name,':','|')); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------ >> Nested Loop (cost=0.01..259.92 rows=491 width=18) >> -> Seq Scan on element t (cost=0.00..13.01 rows=701 width=9) >> -> Index Scan using element_ftsidx_test on element s (cost=0.01..0.33 rows=1 width=9) >> Index Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text))) >> (4 rows) >> >> I have index: "element_ftsidx_test" gin (to_tsvector('testcfg'::regconfig, name::text)) >> >> The same index and query in 8.4.2: >> >> postgres=# explain SELECT s.name as source , t.name as target FROM element as s, element as t WHERE to_tsvector('testcfg',s.name) @@ to_tsquery('testcfg',replace(t.name,':','|')) ; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------ >> Nested Loop (cost=0.32..3123.51 rows=2457 width=18) >> -> Seq Scan on element t (cost=0.00..13.01 rows=701 width=9) >> -> Bitmap Heap Scan on element s (cost=0.32..4.36 rows=4 width=9) Recheck Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text))) >> -> Bitmap Index Scan on element_ftsidx_test (cost=0.00..0.32 rows=4 width=0) >> Index Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text))) >> (6 rows) >> >> Why the query plans are different and why? Thanks! > > Because the row estimates changed, since 8.4 improved row estimation for > TSearch. The 2nd query is probably actually faster, no? If not, you > may need to increase your stats collection. Or at least show us a > VACUUM ANALYZE. I'm sure you mean explain analyze :) -- Postgresql & php tutorials http://www.designmagick.com/