From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Jake Stride <nsuk(at)users(dot)sourceforge(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Indexes |
Date: | 2005-08-02 12:28:27 |
Message-ID: | 42EF66EB.3010105@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Jake Stride wrote:
>
> explain analyse SELECT companycontactmethod.tag,
> companycontactmethod.contact, companycontactmethod."type",
> companycontactmethod.companyid FROM companycontactmethod WHERE
> companycontactmethod.main AND companycontactmethod.type = 'E';
> QUERY PLAN
> ------------------------------------------------------------------------------------------------------------------------
> Seq Scan on companycontactmethod (cost=0.00..181.10 rows=2079
> width=40) (actual time=0.027..17.068 rows=2134 loops=1)
> Filter: (main AND ("type" = 'E'::bpchar))
> Total runtime: 25.965 ms
>
> why is it not using the companycontactmethod_main_type index on the
> query? Am I missing something obvious here?
Well, it's returning 2000 rows, so unless the table is much larger than
that (say 25000 rows or more) then a seq-scan will be faster. Don't
forget that PG will have to load a whole page at a time when it accesses
the disk, so worst case you could end up reading one page (containing
say 20 rows) for every row in your result.
In addition, an index on boolean THEN char is unlikely to be very selective.
To test, execute "SET enable_seqscan=false;" then run your explain
analyse again - that should force it to use the index.
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Wilson | 2005-08-02 12:28:57 | Re: Indexes |
Previous Message | Josef Springer | 2005-08-02 12:18:18 | Re: unicode error on win32 Was: Re: pgmonitor |