
CREATE TABLE foo (c1 integer, c2 text); INSERT INTO foo SELECT i, md5(random()::text) FROM generate_series(1, 1000000) AS i; EXPLAIN SELECT * FROM foo; QUERY PLAN
- Seq Scan on foo (cost = 0.00..18334.00 rows = 1000000 width = 37)
(1 row)
Seq Scan is being used - sequential, block by block, reading data from the foo table.cost ? This is not a time, but a certain spherical notion in a vacuum, designed to estimate the cost of the operation. The first value of 0.00 is the cost of getting the first row. The second - 18334.00 - the cost of obtaining all the lines.rows - the approximate number of rows returned when performing a Seq Scan operation. This value is returned by the scheduler. In my case, it coincides with the actual number of rows in the table.width - the average size of a single line in bytes. INSERT INTO foo SELECT i, md5(random()::text) FROM generate_series(1, 10) AS i; EXPLAIN SELECT * FROM foo; QUERY PLAN
- Seq Scan on foo (cost = 0.00..18334.00 rows = 1000000 width = 37)
(1 row)
rows value has not changed. Statistics on the table is old. To update the statistics, call the ANALYZE command. ANALYZE foo; EXPLAIN SELECT * FROM foo; QUERY PLAN
- Seq Scan on foo (cost = 0.00..18334.10 rows = 1000010 width = 37)
(1 row)
rows displays the correct number of rows.default_statistics_target parameter.EXPLAIN (ANALYZE) . EXPLAIN (ANALYZE) SELECT * FROM foo; QUERY PLAN
- Seq Scan on foo (cost = 0.00..18334.10 rows = 1000010 width = 37) (actual time = 0.012..61.524 rows = 1000010 loops = 1)
Total runtime: 90.944 ms
(2 rows)
actual time - real time in milliseconds, spent to get the first row and all rows, respectively.rows - the actual number of rows received by Seq Scan .loops - how many times you had to perform the Seq Scan operation.Total runtime - the total time of the request.Source: https://habr.com/ru/post/203320/
All Articles