Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0A0611337B4E for ; Mon, 11 Oct 2010 07:09:14 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 39265-07 for ; Mon, 11 Oct 2010 10:09:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 26.mail-out.ovh.net (26.mail-out.ovh.net [91.121.27.225]) by mail.postgresql.org (Postfix) with SMTP id 355691337B4B for ; Mon, 11 Oct 2010 07:09:05 -0300 (ADT) Received: (qmail 15872 invoked by uid 503); 11 Oct 2010 10:14:04 -0000 Received: from b6.ovh.net (HELO mail612.ha.ovh.net) (213.186.33.56) by 26.mail-out.ovh.net with SMTP; 11 Oct 2010 10:14:03 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 11 Oct 2010 12:09:03 +0200 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13) (lists%peufeu.com@88.161.102.87) by ns0.ovh.net with SMTP; 11 Oct 2010 12:09:03 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: pgsql-performance@postgresql.org, "Neil Whelchel" Subject: Re: Slow count(*) again... References: <201010091626.18636.neil.whelchel@gmail.com> Date: Mon, 11 Oct 2010 12:09:02 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: <201010091626.18636.neil.whelchel@gmail.com> User-Agent: Opera Mail/10.62 (Linux) X-Ovh-Tracer-Id: 16302749177594709553 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201010/111 X-Sequence-Number: 40530 > I ran into a fine example of this when I was searching this mailing list, > "Searching in 856,646 pages took 13.48202 seconds. Site search powered by > PostgreSQL 8.3." Obviously at some point count(*) came into play here Well, tsearch full text search is excellent, but it has to work inside the limits of the postgres database itself, which means row visibility checks, and therefore, yes, extremely slow count(*) on large result sets when the tables are not cached in RAM. Also, if you want to use custom sorting (like by date, thread, etc) possibly all the matching rows will have to be read and sorted. Consider, for example, the Xapian full text search engine. It is not MVCC (it is single writer, multiple reader, so only one process can update the index at a time, but readers are not locked out during writes). Of course, you would never want something like that for your main database ! However, in its particular application, which is multi-criteria full text search (and flexible sorting of results), it just nukes tsearch2 on datasets not cached in RAM, simply because everything in it including disk layout etc, has been optimized for the application. Lucene is similar (but I have not benchmarked it versus tsearch2, so I can't tell). So, if your full text search is a problem, just use Xapian. You can update the Xapian index from a postgres trigger (using an independent process, or simply, a plpython trigger using the python Xapian bindings). You can query it using an extra process acting as a server, or you can write a set-returning plpython function which performs Xapian searches, and you can join the results to your tables. > Pg will never have such a fast count() as MyISAM does or the same > insanely fast read performance, Benchmark it you'll see, MyISAM is faster than postgres for "small simple selects", only if : - pg doesn't use prepared queries (planning time takes longer than a really simple select) - myisam can use index-only access - noone is writing to the myisam table at the moment, obviously On equal grounds (ie, SELECT * FROM table WHERE pk = value) there is no difference. The TCP/IP overhead is larger than the query anyway, you have to use unix sockets on both to get valid timings. Since by default on localhost MySQL seems to use unix sockets and PG uses tcp/ip, PG seem 2x slower, which is in fact not true.