I have read references of cost of SQL statement everywhere in databases. What exactly does it mean? So this is the number of statements to be executed or something?
6 Answers
Cost is rough measure of how much CPU time and disk I/O server must spend to execute the query.
Typically cost is split into few components:
- Cost to parse the query - it can be non-trivial just to understand what you are asking for.
- Cost to get data from disk and access indexes if it reduces the cost.
- Cost to compute some mathematical operations on your data.
- Cost to group or sort data.
- Cost to deliver data back to client.

- 111,019
- 13
- 122
- 148
The cost is an arbitrary number that is higher if the CPU time/IO/Memory is higher. It is also vendor specific.

- 44,617
- 6
- 35
- 64
It means how much it will "cost" you to run a specific SQL query in terms of CPU, IO, etc. For example Query A can cost you 1.2sec and Query B can cost you 1.8sec
See here: Measuring Query Performance : "Execution Plan Query Cost" vs "Time Taken"
Cost of a query relates to how much CPU utilization and time will query take. This is an estimated value, your query might take less or more time depending on the data. If your tables and all the indexes of that table are analyzed(analyze table table_name compute statistics for table for all indexes for all indexed columns) then cost based result's estimate will suffice with your query execution time.

- 492
- 3
- 17
Theoretically the above answers can satisfy you.But when you are on the floor working here is an insight.
Practically you can access the cost by the number of seeks and scans your SQL query takes.
Go to Execution Plan and accordingly you will be able to optimize the amount of time (roughly the cost) your query takes. A sample execution plan looks like this :

- 4,905
- 1
- 17
- 17