X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id C73F89FB274 for ; Tue, 22 Aug 2006 14:23:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 96239-10 for ; Tue, 22 Aug 2006 17:23:04 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.de [213.165.64.20]) by postgresql.org (Postfix) with SMTP id 3114E9FA50F for ; Tue, 22 Aug 2006 14:23:03 -0300 (ADT) Received: (qmail invoked by alias); 22 Aug 2006 17:23:02 -0000 Received: from reverse-213-146-112-9.cust.kamp-dsl.de (EHLO salaam.bg8net) [213.146.112.9] by mail.gmx.net (mp036) with SMTP; 22 Aug 2006 19:23:02 +0200 X-Authenticated: #5277147 Received: from localhost (localhost [127.0.0.1]) by salaam.bg8net (Postfix) with ESMTP id 84EC342F9E for ; Tue, 22 Aug 2006 19:23:01 +0200 (CEST) From: Ulrich Habel Reply-To: espero7757@gmx.net To: pgsql-performance@postgresql.org Subject: query planner: automatic rescribe of LIKE to BETWEEN ? Date: Tue, 22 Aug 2006 19:22:59 +0200 User-Agent: KMail/1.9.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200608221922.59734.espero7757@gmx.net> X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.951 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, SPF_HELO_SOFTFAIL, SPF_SOFTFAIL X-Spam-Level: *** X-Archive-Number: 200608/348 X-Sequence-Number: 20533 Hello all, had an idea of optimizing a query that may work generally. In case a 'column' is indexed, following two alterations could be done I think: A) select ... where column ~ '^Foo' --> Seq Scan into that: select ... where column BETWEEN 'Foo' AND 'FooZ' --> Index Scan of course 'Z' should be the last possible character internally used of the DBMS. That would work as long as there is no in-case-sensitive search being done. another rescribtion: B) select ... where column ~ '^Foo$' --> Seq Scan into that: select ... where column = 'Foo' --> Bitmap Heap Scan That speeds up things, too. That would also apply to 'LIKE' and 'SIMILAR TO' operations, I think. Is there any idea to make the "Query Planner" more intelligent to do these convertions automatically? Anythings speeks against this hack? Regards Uli Habel