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=# 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 ---------------------------------------------------- Seq Scan on t1 (cost=0.00..18.10 rows=3 width=96) Filter: (c1 = 2::numeric) (2 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=# 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 -- Execution result. gaussdb=# EXPLAIN SELECT * FROM t1 WHERE c1 <= 80000; QUERY PLAN -------------------------------------------------------- Seq Scan on t1 (cost=0.00..783.86 rows=9356 width=96) Filter: (c1 <= 80000::numeric) (2 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.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot