X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 27663D1B21B for ; Tue, 15 Jun 2004 09:44:03 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33012-04 for ; Tue, 15 Jun 2004 12:43:57 +0000 (GMT) Received: from mail.autorevenue.com (ip-208.178.167.106.gblx.net [208.178.167.106]) by svr1.postgresql.org (Postfix) with ESMTP id B3148D1B20E for ; Tue, 15 Jun 2004 09:43:52 -0300 (ADT) Received: from jeremydunn ([192.168.1.79]) (authenticated) by mail.autorevenue.com (8.11.6/8.11.6) with ESMTP id i5FChqL17257; Tue, 15 Jun 2004 08:43:52 -0400 Reply-To: From: "Jeremy Dunn" To: "'borajetta'" Cc: "Postgresql Performance" Subject: Re: 50 000 000 Table entries and I have to do a keyword search HELP NEEDED Date: Tue, 15 Jun 2004 08:43:49 -0400 Organization: AutoRevenue Message-ID: <000601c452d6$68263570$4f01a8c0@jeremydunn> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0007_01C452B4.E1149570" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 In-Reply-To: Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.6 tagged_above=0.0 required=5.0 tests=HTML_40_50, HTML_FONTCOLOR_BLUE, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200406/154 X-Sequence-Number: 7212 This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C452B4.E1149570 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit One option that does not take advantage of any fancy indexing methods is to create a trigger on the table, on insert/update/delete, which extracts each individual word from the field you care about, and creates an entry in another 'keyword' table, id = 'word', value = pk of your original table. then index the keyword table on the 'keyword' field, and do your searches from there. this should improve performance substantially, even on very large return sets, because the keyword table rows are very small and thus a lot of them fit in a disk block. - Jeremy -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of borajetta Sent: Monday, June 07, 2004 5:47 PM To: pgsql-performance@postgresql.org Subject: [PERFORM] 50 000 000 Table entries and I have to do a keyword search HELP NEEDED So I have a table with about 50 million entries in it, I have to do a keyword search. The keyword search is done on the title of the entry. For example a entry could be "This is a title string which could be searched" I have tried a few ways to search but I get horrible search times. Some keywords will come up with matches as big as .25 million but most are around 1000-5000. I use an index which narrows the table down to about 1.5-2million entries. I used 2 tables which had a 1:1 correspondence. One held a gist index which was on a int field which searched the for the keyword. Then I would join the table to another to retrieve the rest of the information about the items it matched. This was slow even for returning 100 entries. About 10 seconds, sometimes 5. But when I start getting 1xxx entries its about 30-50 seconds. The rest is just horrible. How should I set up my indexes and or tables. We were thinking of putting the index inside one table then the join would not have to be done but this still returns rather slow results. I have not fully tested this method but it looks like when run for just the keyword search on the title and no joining it can return in about 10 seconds or less. This is a great improvement but I am currently going to make the table all in one and see how long it will take. I believe it will not be much more as there will be no join needed only the returning of some attribute fields. This is still not the kind of time I would like to see, I wanted something around 2 seconds or less. I know there is a lot of information especially if .25 million rows are to be returned but if there is only 1xxx-9xxx rows to be returned I believe 2 seconds seems about right. How do search engines do it? Any suggestions are welcome, Thanks ------=_NextPart_000_0007_01C452B4.E1149570 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Message
One=20 option that does not take advantage of any fancy indexing methods is to cre= ate a=20 trigger on the table, on insert/update/delete, which extracts each individu= al=20 word from the field you care about, and creates an entry in another 'keywor= d'=20 table, id =3D 'word', value =3D pk of your original table.  then index= the=20 keyword table on the 'keyword' field, and do your searches from there. = ;=20 this should improve performance substantially, even on very large return se= ts,=20 because the keyword table rows are very small and thus a lot of them fit in= a=20 disk block.
 
-=20 Jeremy
-----Original Message-----
From:=20 pgsql-performance-owner@postgresql.org=20 [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of=20 borajetta
Sent: Monday, June 07, 2004 5:47 PM
To:= =20 pgsql-performance@postgresql.org
Subject: [PERFORM] 50 000 000 = Table=20 entries and I have to do a keyword search HELP NEEDED

So I have a table with about 50 million entries in it, I have to= do a=20 keyword search.

 

The keyword search is done on the title of the entry.  For example a entry could be "T= his is=20 a title string which could be searched"

 

I have tried a few ways to search but I get horrible search time= s.  Some keywords will come up with= =20 matches as big as .25 million but most are around 1000-5000.

 

I use an index which narrows the table down to about 1.5-2millio= n=20 entries.

 

I used 2 tables which had a 1:1 correspondence.

One held a gist index which was on a int field which searched th= e for=20 the keyword.  Then I would = join=20 the table to another to retrieve the rest of the information about the it= ems=20 it matched.

 

This was slow even for returning 100 entries.  About 10 seconds, sometimes 5.<= SPAN=20 style=3D"mso-spacerun: yes">  But when I start getting 1xxx e= ntries=20 its about 30-50 seconds.  T= he rest=20 is just horrible.

 

How should I set up my indexes and or tables.

We were thinking of putting the index inside one table then the = join=20 would not have to be done but this still returns rather slow=20 results.

 

I have not fully tested this method but it looks like when run f= or just=20 the keyword search on the title and no joining it can return in about 10= =20 seconds or less.

This is a great improvement but I am currently g= oing to=20 make the table all in one and see how long it will take.  I believe it will not be much m= ore as=20 there will be no join needed only the returning of some attribute fields.=  

 

This is still not the kind of time I would like to see, I wanted= =20 something around 2 seconds or less.&nbs= p;=20 I know there is a lot of information especially if .25 million row= s are=20 to be returned but if there is only 1xxx-9xxx rows to be returned I belie= ve 2=20 seconds seems about right.

 

How do search engines do it?

Any suggestions are welcome,

 

Thanks

------=_NextPart_000_0007_01C452B4.E1149570--