{SOLVED?] Re: [GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Ivan Sergio Borgonovo
On Thu, 10 Jul 2008 10:46:53 -0400 Tom Lane <[EMAIL PROTECTED]> wrote: > This sub-select is non optimizable because you've got an outer > reference in it, which compels re-evaluating it at every row of > the outer query. Try recasting as > explain select i1.brands, i1.name, i1.dataPub, i1.datains

Re: [GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Ivan Sergio Borgonovo
On Thu, 10 Jul 2008 10:46:53 -0400 Tom Lane <[EMAIL PROTECTED]> wrote: > Ivan Sergio Borgonovo <[EMAIL PROTECTED]> writes: > > Now I try this: > > > explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento > > from catalog_items i1 > > inner join catalog_brands b1 on upper(i1.brands)

Re: [GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Tom Lane
Ivan Sergio Borgonovo <[EMAIL PROTECTED]> writes: > Now I try this: > explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento > from catalog_items i1 > inner join catalog_brands b1 on upper(i1.brands)=upper(b1.name) > where i1.ItemID in ( > select i2.ItemID from catalog_items i2

Re: [GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Martijn van Oosterhout
On Thu, Jul 10, 2008 at 11:40:40AM +0200, Ivan Sergio Borgonovo wrote: > I've this: What's basically killing you is this condition: > select i2.ItemID from catalog_items i2 > inner join catalog_brands b2 on upper(i2.brands)=upper(b2.name) > where i1.brands=i2.brands <* > an

[GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Ivan Sergio Borgonovo
I've this: CREATE TABLE catalog_brands ( brandid serial NOT NULL, "name" character varying(64) NOT NULL, delivery smallint NOT NULL DEFAULT (24 * 15), deliverymessage character varying(64), brandtypeid integer, brandgroupid integer, CONSTRAINT catalog_brands_pkey PRIMARY KEY (brandid

Re: [GENERAL] Functional index adding one

2008-07-03 Thread Sam Mason
On Thu, Jul 03, 2008 at 11:11:26AM -0400, Tom Lane wrote: > Sam Mason <[EMAIL PROTECTED]> writes: > > Not entirely sure why, but it'll probably have > > something to do with avoiding ambiguity in the grammar. > > Right. The problem is the Berkeley-era decision to put index opclasses > into the sy

Re: [GENERAL] Functional index adding one

2008-07-03 Thread Tom Lane
Sam Mason <[EMAIL PROTECTED]> writes: > You just want an extra set of brackets; i.e.: > CREATE INDEX token_position_func ON token ((position+1)); > Should do the trick. Not entirely sure why, but it'll probably have > something to do with avoiding ambiguity in the grammar. Right. The problem

Re: [GENERAL] Functional index adding one

2008-07-03 Thread Gregory Stark
"Gregory Stark" <[EMAIL PROTECTED]> writes: > CREATE INDEX token_position_func on (token(position+1)) Ooops, I misread that as if "token" were a function and not the table. Sam Mason had the right syntax. Sorry. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me ab

Re: [GENERAL] Functional index adding one

2008-07-03 Thread Gregory Stark
<[EMAIL PROTECTED]> writes: > Hi all: > > I'm trying to create a functional index into column position of token > table (see below). I want to make something like: > > CREATE INDEX token_position_func > ON token (position+1); > > but I get: > > test=# CREATE INDEX token_position_func > test-# ON t

Re: [GENERAL] Functional index adding one

2008-07-03 Thread Sam Mason
On Thu, Jul 03, 2008 at 11:50:39AM +0200, [EMAIL PROTECTED] wrote: > test=# CREATE INDEX token_position_func > test-# ON token (position+1); > ERROR: syntax error at or near "+" > LINE 2: ON token (position+1); > > I read that I can do "ON function(column)" but, is there a built-in > function in

Re: [GENERAL] Functional index adding one

2008-07-03 Thread A. Kretschmer
am Thu, dem 03.07.2008, um 11:50:39 +0200 mailte [EMAIL PROTECTED] folgendes: > Hi all: > > I'm trying to create a functional index into column position of token > table (see below). I want to make something like: > > CREATE INDEX token_position_func > ON token (position+1); > > but I get: > >

[GENERAL] Functional index adding one

2008-07-03 Thread lbarcala
Hi all: I'm trying to create a functional index into column position of token table (see below). I want to make something like: CREATE INDEX token_position_func ON token (position+1); but I get: test=# CREATE INDEX token_position_func test-# ON token (position+1); ERROR: syntax error at or nea

Re: [GENERAL] Functional Index Question

2008-03-13 Thread Craig Ringer
James B. Byrne wrote: I am considering moving theses sorts of purification routines into the DBMS because I feel that is where they really belong. However, the prevailing sentiment of the community surrounding Rails seems to hold otherwise so I wonder if this is really the right thing to do.

Re: [GENERAL] Functional Index Question

2008-03-13 Thread hubert depesz lubaczewski
On Thu, Mar 13, 2008 at 09:04:28AM -0400, James B. Byrne wrote: > To return to my first question. Is doing this sort of thing considered good a > practice? for me - yes. keeping it in database is the best and safest option. but you might get "issues" with orms. > where they really belong. Howev

Re: [GENERAL] Functional Index Question

2008-03-13 Thread James B. Byrne
On Wed, March 12, 2008 17:02, hubert depesz lubaczewski wrote: > correct way: > select lower(trim(both ' ' from(regexp_replace(' depeSz hub ', E'\\s+', ' ', > 'g' ; > > now. i would suggest *not* to use this as base for index. > > make a wrapper function instead: > > create function cleaned(

Re: [GENERAL] Functional Index Question

2008-03-12 Thread hubert depesz lubaczewski
On Wed, Mar 12, 2008 at 11:46:12AM -0400, James B. Byrne wrote: > CREATE UNIQUE INDEX idxUF_table_column ON table > (lower(trim(both ' ' from(regexp_replace(, /( ){2,}/g," " ) > What I intend this to do is to squeeze out excess whitespace, strip off > leading and trailing blanks, and then for

[GENERAL] Functional Index Question

2008-03-12 Thread James B. Byrne
I am considering the utility value of creating a functional index on a name field. To minimize the number of invalid searches caused by spacing errors and mis-matched lettercase I am contemplating doing something like this: CREATE UNIQUE INDEX idxUF_table_column ON table (lower(trim(both ' ' fr

Re: [GENERAL] Functional Index

2006-11-22 Thread Bernhard Weisshuhn
On Wed, Nov 22, 2006 at 11:24:33AM -0500, Tom Lane <[EMAIL PROTECTED]> wrote: > Stephan Szabo <[EMAIL PROTECTED]> writes: > > On Wed, 22 Nov 2006, Alexander Presber wrote: > >> CREATE INDEX idx_main_subject ON pdb.main (lower(main_subject::text) > >> using varchar_ops); > > > IIRC, unless you're

Re: [GENERAL] Functional Index

2006-11-22 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > On Wed, 22 Nov 2006, Alexander Presber wrote: >> CREATE INDEX idx_main_subject ON pdb.main (lower(main_subject::text) >> using varchar_ops); > IIRC, unless you're in C locale, you'll want varchar_pattern_ops rather > than varchar_ops on the index to make

Re: [GENERAL] Functional Index

2006-11-22 Thread Stephan Szabo
On Wed, 22 Nov 2006, Alexander Presber wrote: > Hello everybody, > > I am trying to speed up a query on an integer column by defining an > index as follows > > > CREATE INDEX idx_main_subject ON pdb.main (lower(main_subject::text) > using varchar_ops); > > on column "main_subject". > > I had hope

Re: [GENERAL] Functional Index

2006-11-22 Thread Teodor Sigaev
use varchar_pattern_ops operator class, LIKE cannot use varchar_ops for non-C locales. Alexander Presber wrote: Hello everybody, I am trying to speed up a query on an integer column by defining an index as follows > CREATE INDEX idx_main_subject ON pdb.main (lower(main_subject::text) usin

[GENERAL] Functional Index

2006-11-22 Thread Alexander Presber
Hello everybody, I am trying to speed up a query on an integer column by defining an index as follows > CREATE INDEX idx_main_subject ON pdb.main (lower(main_subject::text) using varchar_ops); on column "main_subject". I had hoped to get speedups for right-fuzzy LIKE-searches, but EXPLAIN

[GENERAL] functional index "real world" uses

2004-02-05 Thread David Garamond
I want to know how functional indexes are used "in the real world". Here are the common uses: * non-unique index on the first parts of a longish text field (SUBSTRING(field)) to save disk space, while still allowing faster searches than a sequential scan. * indexing on LOWER(field)/UPPER(field

[GENERAL] functional index "real world" uses

2004-02-05 Thread David Garamond
I want to know how functional indexes are used "in the real world". Here are the common uses: * non-unique index on the first parts of a longish text field (SUBSTRING(field)) to save disk space, while still allowing faster searches than a sequential scan. * indexing on LOWER(field)/UPPER(field

Re: [GENERAL] Functional index performance question

2003-09-30 Thread Greg Stark
Arguile <[EMAIL PROTECTED]> writes: > On Tue, 2003-09-30 at 07:06, Mike Mascari wrote: > [snip] > > CREATE INDEX i_employees ON employees(lower(name)); > > > > Let's also assume that the lower() function is computationally > > expensive. Now if I have a query like: > > > > SELECT lower(name) > >

Re: [GENERAL] Functional index performance question

2003-09-30 Thread Arguile
On Tue, 2003-09-30 at 09:54, Mike Mascari wrote: > Arguile wrote: > > > On Tue, 2003-09-30 at 07:06, Mike Mascari wrote: > > > >>CREATE INDEX i_employees ON employees(lower(name)); > >> > >>Let's also assume that the lower() function is computationally > >>expensive. Now if I have a query like: >

Re: [GENERAL] Functional index performance question

2003-09-30 Thread Mike Mascari
Arguile wrote: > On Tue, 2003-09-30 at 07:06, Mike Mascari wrote: > >>CREATE INDEX i_employees ON employees(lower(name)); >> >>Let's also assume that the lower() function is computationally >>expensive. Now if I have a query like: >> >>SELECT lower(name) >>FROM employees >>WHERE lower(name) = 'mik

Re: [GENERAL] Functional index performance question

2003-09-30 Thread Tom Lane
Arguile <[EMAIL PROTECTED]> writes: > On Tue, 2003-09-30 at 07:06, Mike Mascari wrote: >> SELECT lower(name) >> FROM employees >> WHERE lower(name) = 'mike' >> >> will PostgreSQL re-evaluate lower(name)? Is it necessary? > No, it won't re-evaluate. I think he's asking whether the lower(name) app

Re: [GENERAL] Functional index performance question

2003-09-30 Thread Arguile
On Tue, 2003-09-30 at 07:06, Mike Mascari wrote: [snip] > CREATE INDEX i_employees ON employees(lower(name)); > > Let's also assume that the lower() function is computationally > expensive. Now if I have a query like: > > SELECT lower(name) > FROM employees > WHERE lower(name) = 'mike' > > will

[GENERAL] Functional index performance question

2003-09-30 Thread Mike Mascari
Let's assume I have a table like so: CREATE TABLE employees ( employeeid text not null, name text not null ); CREATE INDEX i_employees ON employees(lower(name)); Let's also assume that the lower() function is computationally expensive. Now if I have a query like: SELECT lower(name) FROM emplo