Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the cost of SqL statement means?

Tags:

sql

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?

like image 714
Vivek Gaur Avatar asked Jan 13 '23 02:01

Vivek Gaur


2 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.
like image 97
mvp Avatar answered Jan 20 '23 06:01

mvp


The cost is an arbitrary number that is higher if the CPU time/IO/Memory is higher. It is also vendor specific.

like image 26
Scary Wombat Avatar answered Jan 20 '23 08:01

Scary Wombat