Sample Scan
Description
Sample scan is a method of scanning tables. It can randomly extract some data from a table for query instead of scanning the entire table. Sample scan is used together with the TABLESAMPLE keyword in [ TABLESAMPLE sampling_method ( argument [, ...] ) [ REPEATABLE ( seed ) ] ] mode. This technology is usually used in a query scenario in which a large table or random sampling is required, to improve query efficiency.
Typical Scenarios
When the tablesample syntax is used for query, sampling_method is set to system or bernoulli.
Examples
Example: Query the sampling data.
-- 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 c1 FROM t1 tablesample system(10); QUERY PLAN ------------------------------------------------------------- Streaming (type: GATHER) (cost=0.06..4.11 rows=2 width=32) Node/s: All datanodes -> Sample Scan on t1 (cost=0.00..4.02 rows=2 width=32) Sampling: system (10::real) (4 rows) -- Drop. gaussdb=# DROP TABLE t1;
In the preceding example, the output of the sample scan operator is as follows.
Item |
Description |
---|---|
Sample Scan |
Operator name. |
Sampling |
Operator sampling mode. In the example, system is used as the sampling method, and the sampling ratio is 10%. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.