From sidarlopez@hotmail.com Wed Mar 26 22:18:10 2003 X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 43410476285 for ; Wed, 26 Mar 2003 17:18:10 -0500 (EST) Received: from hotmail.com (oe61.law14.hotmail.com [64.4.20.196]) by postgresql.org (Postfix) with ESMTP id 5671D475F2C for ; Wed, 26 Mar 2003 17:18:09 -0500 (EST) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 26 Mar 2003 14:18:11 -0800 Received: from 196.40.3.198 by oe61.law14.hotmail.com with DAV; Wed, 26 Mar 2003 22:18:10 +0000 X-Originating-IP: [196.40.3.198] X-Originating-Email: [sidarlopez@hotmail.com] From: "Sidar Lopez Cruz" To: Subject: search on tables Date: Wed, 26 Mar 2003 16:26:35 -0600 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000B_01C2F3B4.7837F070" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: X-OriginalArrivalTime: 26 Mar 2003 22:18:11.0016 (UTC) FILETIME=[960B0480:01C2F3E5] X-Spam-Status: No, hits=-0.9 required=5.0 tests=BAYES_30,HTML_30_40 version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/448 X-Sequence-Number: 8088 This is a multi-part message in MIME format. ------=_NextPart_000_000B_01C2F3B4.7837F070 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable why searching with like or ilike on tables with too many records is too slo= w? i have a table like this create table sujetos (cedula varchar(20) not null primary key, nombre varch= ar(255), id_tipo_documento bigint); create index idx_nombre on sujetos (nombre); and them, i insert 5,000,000 of records from mssql then, i do something like that, select * from sujetos where nombre like 'LO= PEZ CRUZ SIDAR%', and the request from the server is normal, but when i do = this, select * from sujetos where nombre like 'lopez%sidar%'; the server die.... searching this string.... :-) Sidar Lopez Cruz - Cero Riesgo, S.A. ------=_NextPart_000_000B_01C2F3B4.7837F070 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
why searching with like or ilike on tables= with too=20 many records is too slow?
i have a table like this
 
create table sujetos (cedula varchar(20) n= ot null=20 primary key, nombre varchar(255), id_tipo_documento bigint);
create index idx_nombre on sujetos=20 (nombre);
 
and them, i insert 5,000,000 of records fr= om=20 mssql
 
then, i do something like that, select * f= rom=20 sujetos where nombre like 'LOPEZ CRUZ SIDAR%', and the request from the ser= ver=20 is normal, but when i do this, select * from sujetos where nombre like=20 'lopez%sidar%';
 
the server die.... searching this=20 string....

:-) Sidar Lopez Cruz
- Cero Riesgo,= =20 S.A.
------=_NextPart_000_000B_01C2F3B4.7837F070-- From nikolaus@dilger.cc Thu Mar 27 02:14:53 2003 X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 789EA475CBC for ; Wed, 26 Mar 2003 21:14:53 -0500 (EST) Received: from c001.snv.cp.net (h000.c001.snv.cp.net [209.228.32.114]) by postgresql.org (Postfix) with SMTP id B185F47580B for ; Wed, 26 Mar 2003 21:14:52 -0500 (EST) Received: (cpmta 20667 invoked from network); 26 Mar 2003 18:14:55 -0800 Received: from 209.228.32.131 (HELO mail.dilger.cc.criticalpath.net) by smtp.register-admin.com (209.228.32.114) with SMTP; 26 Mar 2003 18:14:55 -0800 X-Sent: 27 Mar 2003 02:14:55 GMT Received: from [216.68.146.219] by mail.dilger.cc with HTTP; Wed, 26 Mar 2003 18:14:55 -0800 (PST) Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 To: sidarlopez@hotmail.com Cc: pgsql-admin@postgresql.org From: "Nikolaus Dilger" Subject: Re: search on tables X-Sent-From: nikolaus@dilger.cc Date: Wed, 26 Mar 2003 18:14:55 -0800 (PST) X-Mailer: Web Mail 5.2.3-0_sol28 Message-Id: <20030326181455.20258.h017.c001.wm@mail.dilger.cc.criticalpath.net> X-Spam-Status: No, hits=-13.1 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/449 X-Sequence-Number: 8089 Sidar, 1) nombre like 'LOPEZ CRUZ SIDAR%' is much more selective than 2) nombre like 'lopez%sidar%' The database needs to get all rows that match up to the first wildcard. In 1) that is most likely a very low number and your index will help PostgreSQL to find those rows quickly. In 2) that is potetially 1,000s of rows out of the 5,000,000 in your table. In a second step the end result is selected from the records that match 'lopez%' =46rom a performance standpoint the worst you can do with LIKE is to have the wildcard at the very beginning.=20 Then PostgreSQL needs to read all records. For example WHERE nombre LIKE '%lopez%'; However, this may get you a match for "Jennifer Lopez". Many applications have a column first_name and another for last_name. Then you can have a more selective WHERE clause WHERE last_name=3D'Lopez' AND first_name like 'J%' Regards, Nikolaus Dilger On Wed, 26 Mar 2003, "Sidar Lopez Cruz" wrote: why searching with like or ilike on tables with too=20 many records is too slow? i have a table like this =A0 create table sujetos (cedula varchar(20) not null=20 primary key, nombre varchar(255), id_tipo_documento bigint); create index idx_nombre on sujetos=20 (nombre); =A0 and them, i insert 5,000,000 of records from=20 mssql =A0 then, i do something like that, select * from=20 sujetos where nombre like 'LOPEZ CRUZ SIDAR%', and the request from the server=20 is normal, but when i do this, select * from sujetos where nombre like=20 'lopez%sidar%'; =A0 the server die.... searching this=20 string.... :-) Sidar Lopez Cruz- Cero Riesgo,=20 S.A.