Re: Can't get planner to use multicolumn index on large

From: Neil Conway <neilc(at)samurai(dot)com>
To: Ulrich Meis <u(dot)meis(at)gmx(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Can't get planner to use multicolumn index on large
Date: 2004-11-24 13:06:38
Message-ID: 41A4875E.2070609@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ulrich Meis wrote:
> CREATE TABLE data.question_result (
> id bigserial PRIMARY KEY,
> trial_id bigint NOT NULL REFERENCES data.trial(id),
> question_id bigint REFERENCES content.question(id),
> <two more columns>,
> );

> mydb=# explain analyze select * from data.question_result where trial_id=1
> and question_id=2;

This is a well-known optimizer deficiency. You need to single-quote the
numeric literals or cast them to the type of the column, or else you
won't get index scans for non-int4 columns. In other words:

explain analyze select * from data.question_result where trial_id='1'
and question_id='2'

This is fixed in 8.0

-Neil

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2004-11-24 13:24:43 Re: Creating index on a view?
Previous Message Ulrich Meis 2004-11-24 12:33:04 Can't get planner to use multicolumn index on large table