Automatic Indexes from Query Optimization?

From: Daryl Beattie <dbeattie(at)insystems(dot)com>
To: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Automatic Indexes from Query Optimization?
Date: 2002-09-18 13:31:00
Message-ID: 4160E6FC08ABD21191F000805F857E9305ECE3FE@mail.markham.insystems.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dear PostgreSQL people,

I did some browsing through the docs, and I still haven't found a
simple yes/no answer to these questions:
Are indexes created automatically by the query optimizer? Or does
the query optimizer only optimize lone queries? I assume it only optimizes
queries, and does not optimize the database depending on how it is used.
Perhaps what I am thinking of is not a query optimizer but more like a
relation-optimizer.
Does the query optimizer remember optimizations it does for queries
that are run over and over with different parameters?
A concrete example would be if I created a table like this:

CREATE TABLE Food (
Id SERIAL PRIMARY KEY,
Name VARCHAR(10)
);

and I run, say, 10,000 ILIKE queries on Name, is the query optimizer
smart enough to create an index on lower(Name) and change subsequent queries
to use a lower() comparison instead of an ILIKE comparison? [This is
probably a bad example because it is likely that a ILIKE b is not equivalent
to lower(a) = lower(b) in every case. However, it does illustrate where
automatic index creation coupled with query optimization would improve
performance.]
A further question I have is; if indexes are created by the DBA,
will the query optimizer know to use them? For example, it would be a bad
situation if there was a lower(Name) index, but the query optimizer
optimized the lower() out of a query because it believed speed would be
increased.
I hope I am asking these questions in the right forum. I am having a
bit of trouble figuring out where the line is drawn in terms of what
optimization I need to do by hand, and what the database can do for itself.

Sincerely,

Daryl.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2002-09-18 13:40:30 Re: Automatic Indexes from Query Optimization?
Previous Message Mihai Gheorghiu 2002-09-18 13:06:40 Re: Help!