Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 0533B9F9F47 for ; Sat, 2 Dec 2006 16:36:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 48218-06 for ; Sat, 2 Dec 2006 16:36:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from globalrelay.com (mail1.globalrelay.com [216.18.71.77]) by postgresql.org (Postfix) with ESMTP id F15089F9392 for ; Sat, 2 Dec 2006 16:36:52 -0400 (AST) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES Received: from [63.226.153.214] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 116429201; Sat, 02 Dec 2006 12:36:50 -0800 From: "Dave Dutcher" To: "'Alexandru Coseru'" , Subject: Re: Regex performance issue Date: Sat, 2 Dec 2006 14:36:49 -0600 Message-ID: <030b01c71651$984577c0$8300a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 In-reply-to: <00d901c71644$326b0490$3cb16956@alex> Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50 X-Spam-Level: X-Archive-Number: 200612/14 X-Sequence-Number: 22070 > -----Original Message----- > From: pgsql-performance-owner@postgresql.org On Behalf Of Alexandru = Coseru > asterisk=3D> explain analyze SELECT * FROM destlist WHERE=20 > '0039051248787' ~=20 > prefix AND id_ent=3D'-2' AND dir=3D0 ORDER by length(prefix) DESC; > > =20 > QUERY PLAN > -------------------------------------------------------------- > ---------------------------------------------------------------------- > Sort (cost=3D7925.07..7925.15 rows=3D31 width=3D67) (actual=20 > time=3D857.715..857.716 rows=3D2 loops=3D1) > Sort Key: length((prefix)::text) > -> Bitmap Heap Scan on destlist (cost=3D60.16..7924.30=20 > rows=3D31 width=3D67)=20 > (actual time=3D2.156..857.686 rows=3D2 loops=3D1) > Recheck Cond: ((id_ent =3D -2) AND (dir =3D 0)) > Filter: ('0039051248787'::text ~ (prefix)::text) > -> Bitmap Index Scan on destlist_indx2 (cost=3D0.00..60.16=20 > rows=3D6193 width=3D0) (actual time=3D1.961..1.961 rows=3D5205 = loops=3D1) > Index Cond: ((id_ent =3D -2) AND (dir =3D 0)) > Total runtime: 857.804 ms > (8 rows) >=20 > > "mmumu" btree (prefix varchar_pattern_ops) >=20 I'm surpised Postgres isn't using the index on prefix seeing as the = index uses the varchar_pattern_ops operator class. It could be that the index isn't selective enough, or is Postgres not able to use an index with = Posix regular expressions? The docs seem to say that it can, but I'd be = curious to see what happens if you use LIKE instead of ~.=20 Dave =20