Seq Scan
Description
The Seq scan operator is a universal one. It scans a table in a certain direction (forward or backward) and returns all rows that meet the filter criteria.
Typical Scenarios
- The table has no index and needs to be scanned.
- The table has indexes, but most of the data in the table needs to be scanned.
Examples
Example 1: The table has no index and needs to be scanned.
-- Prepare data. gaussdb=# DROP TABLE IF EXISTS t1; gaussdb=# CREATE TABLE t1 (c1 number, c2 number, c3 number); CREATE TABLE gaussdb=# INSERT INTO t1 VALUES(generate_series(1,100), 2, 3); INSERT 0 100 -- Execution result. gaussdb=# EXPLAIN SELECT * FROM t1 WHERE c1 = 2; QUERY PLAN -------------------------------------------------------------- Streaming (type: GATHER) (cost=0.06..13.26 rows=1 width=96) Node/s: datanode1 -> Seq Scan on t1 (cost=0.00..13.16 rows=1 width=96) Filter: (c1 = 2::numeric) (4 rows) -- Drop the table. gaussdb=# DROP TABLE t1;
In the preceding example, the output of the Seq scan operator is described in Table 1.
Item |
Description |
---|---|
Seq Scan |
Operator name. |
Filter |
Filter predicate of the operator. In the example, the filter condition is the value of column c1 is 2. When a query is executed, rows that meet these conditions are included in the final result set. |
Example 2: The table has indexes, but most of the data in the table needs to be scanned.
-- Prepare data. gaussdb=# DROP TABLE IF EXISTS t1; gaussdb=# CREATE TABLE t1(c1 number, c2 number, c3 number); CREATE TABLE gaussdb=# CREATE INDEX idx_c1 on t1(c1); CREATE INDEX gaussdb=# INSERT INTO t1 VALUES(generate_series(1, 100000), 2, 3); INSERT 0 100000 -- Collect statistics. gaussdb=# ANALYZE t1; -- Execution result. gaussdb=# EXPLAIN SELECT * FROM t1 WHERE c1 <= 80000; QUERY PLAN -------------------------------------------------------------------- Streaming (type: GATHER) (cost=4.00..4698.38 rows=80136 width=16) Node/s: All datanodes -> Seq Scan on t1 (cost=0.00..942.00 rows=80136 width=16) Filter: (c1 <= 80000::numeric) (4 rows) -- Drop the table. gaussdb=# DROP TABLE t1;
In the preceding example, the output of the Seq scan operator is described in Table 2.
Item |
Description |
---|---|
Seq Scan |
Operator name. |
Filter |
Filter predicate of the operator. In the example, the filter condition is the value of column c1 is less than or equal to 80000. When a query is executed, rows that meet these conditions are included in the final result set. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.