Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 168C71337BA0 for ; Wed, 22 Dec 2010 17:50:29 -0400 (AST) 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 40504-04 for ; Wed, 22 Dec 2010 21:50:20 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 64.mail-out.ovh.net (64.mail-out.ovh.net [91.121.185.65]) by mail.postgresql.org (Postfix) with SMTP id A04271337B88 for ; Wed, 22 Dec 2010 17:50:19 -0400 (AST) Received: (qmail 13027 invoked by uid 503); 22 Dec 2010 21:33:34 -0000 Received: from b9.ovh.net (HELO mail411.ha.ovh.net) (213.186.33.59) by 64.mail-out.ovh.net with SMTP; 22 Dec 2010 21:33:33 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 22 Dec 2010 23:50:17 +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; 22 Dec 2010 23:50:16 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes In-Reply-To: References: Subject: Re: MySQL HandlerSocket - Is this possible in PG? To: "pgsql-performance@postgresql.org" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Date: Wed, 22 Dec 2010 22:50:16 +0100 Message-ID: User-Agent: Opera Mail/10.63 (Linux) X-Ovh-Tracer-Id: 8257349917417604657 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: 201012/284 X-Sequence-Number: 41736 On Wed, 22 Dec 2010 14:17:21 +0100, Michael Ben-Nes wrote: > Thanks, it is most interesting > > -------------------------------------------------- > Michael Ben-Nes - Internet Consultant and Director. > http://www.epoch.co.il - weaving the Net. > Cellular: 054-4848113 > -------------------------------------------------- > In fact, it would be possible to implement something like MySQL HandlerSocket, using the following Very Ugly Hack : This would only work for ultra simple "SELECT 1 row WHERE primary key = constant" queries. - a pooler (separate process) waits for connections - clients connect to the pooler and send queries - pooler accumulates enough queries to justify the overhead of what's going to come next - pooler takes a bunch of queries and encodes them in some custom ad-hoc format (not SQL) - pooler says to postgres "SELECT do_my_queries( serialized data )" - do_my_queries() is a user function (in C) which uses postgres access methods directly (like index access method on primary key), processes queries, and sends results back as binary data - repeat for next batch Nested Loop Index Scan processes about 400.000 rows/s which is 2.5 us/query, maybe you could get into that ballpark (per core). Of course it's a rather extremely ugly hack. ------------------- Note that you could very possibly have almost the same benefits with "almost" none of the ugliness by doing the following : same as above : - a pooler (separate process) waits for connections - clients connect to the pooler and send queries in the format query + parameters (which libpq uses if you ask) - pooler accumulates enough queries to justify the overhead of what's going to come next different : - pooler looks at each query, and if it has not seen it yet on this particular pg connection, issues a "PREPARE" on the query - pooler sends, in one TCP block, a begin, then a bunch of "execute named prepared statement with parameters" commands, then a rollback - postgres executes all of those and returns all replies in one TCP block (this would need a modification) - pooler distributes results back to clients This would need a very minor change to postgres (coalescing output blocks). It would make the pooler pay TCP overhead instead of postgres, and greatly improve cache locality in postgres. Since error handling would be "problematic" (to say the least...) and expensive it would only work on simple selects.