Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Recheck Cond" in Explain result mean?

From an example in PostgreSQL document:

EXPLAIN SELECT * FROM tenk1 WHERE unique1 < 100 AND stringu1 = 'xxx';                                   QUERY PLAN ------------------------------------------------------------------------------  Bitmap Heap Scan on tenk1  (cost=5.04..229.43 rows=1 width=244)    Recheck Cond: (unique1 < 100)    Filter: (stringu1 = 'xxx'::name)    ->  Bitmap Index Scan on tenk1_unique1  (cost=0.00..5.04 rows=101  width=0)          Index Cond: (unique1 < 100) 

Am I correct that

  • first perform Bitmap Index Scan on all the rows for the first condition, and

  • then on the returned rows, perform Bitmap Heap Scan for the second condition?

Since Bitmap Index Scan already checks the Index Cond on unique1 < 100, why is there "Recheck Cond" on the same condition again in Bitmp heap Scan? What does "Recheck Cond" mean?

I am not sure I understand this related post https://dba.stackexchange.com/questions/106264/recheck-cond-line-in-query-plans-with-a-bitmap-index-scan

Thanks.

like image 920
Tim Avatar asked Jun 21 '18 03:06

Tim


People also ask

What is recheck Cond?

The Recheck Cond is the condition a bitmap scan might use to filter rows out after fetching them. It is only needed if the bitmap scan is lossy, or if it has used any lossy index types that do not guarantee that rows match the condition (BRIN indexes are one example).

What is explain plan in PostgreSQL?

This command displays the execution plan that the PostgreSQL planner generates for the supplied statement. The execution plan shows how the table(s) referenced by the statement will be scanned — by plain sequential scan, index scan, etc.

What is seq scan in Postgres?

Seq Scan. The Seq Scan operation scans the entire relation (table) as stored on disk (like TABLE ACCESS FULL ). Index Scan. The Index Scan performs a B-tree traversal, walks through the leaf nodes to find all matching entries, and fetches the corresponding table data.

What is cost in PostgreSQL?

The cost estimate (cost=0.00.. 5.04 rows=101 width=0) means that Postgres expects that it will “cost” 5.04 of an arbitrary unit of computation to find these values. The 0.00 is the cost at which this node can begin working (in this case, just startup time for the query).


1 Answers

This was explained by Tom Lane on the mailing list:

what is "Recheck condition" and why is it needed?

If the bitmap gets too large we convert it to "lossy" style, in which we only remember which pages contain matching tuples instead of remembering each tuple individually. When that happens, the table-visiting phase has to examine each tuple on the page and recheck the scan condition to see which tuples to return.

like image 119
a_horse_with_no_name Avatar answered Sep 30 '22 23:09

a_horse_with_no_name