Re: constraints in query plans

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Jeremy Drake <pgsql(at)jdrake(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: constraints in query plans
Date: 2006-10-17 17:08:28
Message-ID: 1161104908.31645.106.camel@dogma.v10.wvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, 2006-10-15 at 20:36 -0700, Jeremy Drake wrote:
> I just tried that,
> CREATE INDEX test_domain_k_x1_x2_mp ON test_domain (k, x1, x2, mp);
>
> and dropped the others. That actually works properly.
> jeremyd=# explain analyze select * from test_domain where k = 1255 and mp;
> QUERY PLAN
> ----------------------------------------------------------------------------------------------------------------------------------
> Bitmap Heap Scan on test_domain (cost=5.37..237.21 rows=66 width=17) (actual time=0.115..0.707 rows=132 loops=1)
> Recheck Cond: (k = 1255)
> Filter: mp
> -> Bitmap Index Scan on test_domain_k_x1_x2_mp (cost=0.00..5.37 rows=66 width=0) (actual time=0.081..0.081 rows=132 loops=1)
> Index Cond: ((k = 1255) AND (mp = true))
> Total runtime: 1.137 ms
> (6 rows)
>
> I thought I had to refer to all of the columns in order for this to work,
> that I could not skip some in the middle, but it seems to work.
>

As long as "k=1255" is selective enough, the index is useful. That's
because k is the first item in the index key.

Regards,
Jeff Davis

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Shane Ambler 2006-10-17 17:11:16 Re: Syntax bug? Group by?
Previous Message D'Arcy J.M. Cain 2006-10-17 16:47:21 Re: Syntax bug? Group by?