1

Consider the following plan:

Index Scan using foo_c1_idx1 on foo  (cost=0.00..8.38 rows=1 width=37) (actual time=0.012..0.013 rows=1 loops=1)
  Index Cond: (c1 = 500)
  Buffers: shared hit=4
Total runtime: 0.036 ms

As we can see, the cost to get all rows is 8.38. On my system

SELECT current_setting('random_page_cost');

return 4.

So, as long as the index scan includes 2 random page reading (The first one is to read an index, and the second one to read the actual table), it's not clear what the 0.38 means in the plan?

Could you explain how it's computed?

7
  • 2
    the second one to read the actual table - where? There's nothing in PLAN about reading the "actual table".
    – Matt
    Oct 5, 2015 at 12:50
  • @user4419802 So why do we need two random page accesses?
    – St.Antario
    Oct 5, 2015 at 12:55
  • @user4419802 I mean, by reading the index we get the page the result is contained in. After this we need to read that page (random access)
    – St.Antario
    Oct 5, 2015 at 12:57
  • 5
  • Ah, sorry, I forgot that in PSQL Index scan is actually 'index read + access by rowid'. Then 0.38 is additional "CPU cost".
    – Matt
    Oct 5, 2015 at 13:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.