Re: Recheck condition - Mailing list pgsql-general

From Josh Harrison
Subject Re: Recheck condition
Date
Msg-id 8d89ea1d0711290501g699f65eew9da9031a0f2dfe23@mail.gmail.com
Whole thread Raw
In response to Re: Recheck condition  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: Recheck condition  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
List pgsql-general


> For example if I have a table Person with 3 fields (name,city_id,age). And
> the table contains 1000 rows. The table has 2 indexes city_id and age
> If I have a query :
> SELECT * FROM PERSON WHERE city_id=5 AND AGE=30

The answer is "it depends". Postgres has a cost based planner, it will
estimate the costs of each different way of getting the result and use
the cheapest. The factors that are important is how many rows each
condition will match.

Given your table is only 8MB, the system may decide that it's all in
memory and just do a scan.

Or it maybe see that city_id is almost unique and use that index and
check the matches for the second condition. Or vice-versa.

Or maybe it will scan both indexes, calculate the intersection and then
looks up the matches in the heap (with a recheck).
 
Okay....So If I have a query like the above and the query plan shows  a 'recheck condition' and bitmap scan, then does that mean it scans the indexes first to get the intermediate results and goto the heap only for the final data?
 
Thanks
    jo

pgsql-general by date:

Previous
From: Edoardo Panfili
Date:
Subject: Re: hibernate + postgresql ?
Next
From: Alvaro Herrera
Date:
Subject: Re: Recheck condition