Re: [GENERAL] 50 MB Table - Mailing list pgsql-general

From Karl DeBisschop
Subject Re: [GENERAL] 50 MB Table
Date
Msg-id 200003081343.IAA06868@skillet.infoplease.com
Whole thread Raw
In response to Re: [GENERAL] 50 MB Table  (JB <jimbag@kw.igs.net>)
List pgsql-general
>I've been shuffling thru the 'LIKE' code in pg, but whilst perusing, it
>occurred to me that I could use a function for this thing. Since i'm
>only looking at the first part of the string I use...
>
>SELECT * FROM info WHERE substring(street_name from 1 to 4) = 'MAIN'
>
>...and the query completes in under 2 secs. Stupidly obvious now but I
>thought I would share this blinding insight with the list ;)

if that case, try:

SELECT * FROM info WHERE street_name ~ '^MAIN';

One trick with string indexes in PG is they must be 'front-anchored',
which I thought "LIKE 'MAIN%'" was.  But maybe it's not.

This solution is a little more flexible than substring, and may give
the speed you desire.

(I'm not absolutely sure this query won't have the same performance
problems your first query did, but it typically works for us.  If you
do try this, I'd appreciate knowing whether it works for you or not)

--
Karl DeBisschop <kdebisschop@alert.infoplease.com>
617.542.6500x2332 (Fax: 617.956.2696)

Information Please / Family Education Network
http://www.infoplease.com  - your source for FREE online reference

pgsql-general by date:

Previous
From: "Oliver Elphick"
Date:
Subject: Re: [GENERAL] User authentication problem
Next
From: frank
Date:
Subject: [GENERAL] Accounting/inventory systems