Re: Modifying WHERE input conditions for a VIEW

From: Tony Holmes <tony(at)crosswinds(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Modifying WHERE input conditions for a VIEW
Date: 2003-03-31 15:39:30
Message-ID: 20030331103930.A17777@crosswinds.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On +Mar 30, Tom Lane wrote:
>
> You might be able to make it work efficiently with a functional index.
> To meet the syntactic limitations of functional indexes, you'd need to
> define a function "addfoo(text) returns text" that returns the input
> with "@foo.com" appended. (Be sure to mark it strict and immutable.)
> Now you can create an index on addfoo(username) for foo_users, and
> then your view becomes
>
> CREATE VIEW all_users as
> SELECT uid, addfoo(username) AS username, password, active
> FROM foo_users
> UNION ALL
> SELECT uid, username, password, active
> FROM domain_users
>
> I haven't tested, but I believe 7.3 will optimize this fairly decently
> when the query is "SELECT ... FROM all_users WHERE username = something'.

For not testing this solution works amazingly well! :)

There is 3 orders of magnitude improvement in query speed, making it
suitable for our needs! Now on to the task of fixing our schema and
data.

Thank you Tom. This kind of assistance is exactly what makes PostgreSQL
great! (well, on top of being a superior product, IMHO).

--
Tony Holmes

Founder and Senior Systems Architect
Crosswinds Internet Communications Inc.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Matt Clark 2003-03-31 16:16:07 Alias for data types?
Previous Message Delao, Darryl W 2003-03-31 14:02:01 Re: [NOVICE] Postgres Syslog