MergeAppend
Description
MergeAppend is used to append multiple ordered relationship sets. The operation is similar to Append. The only difference is that MergeAppend accelerates the calculation of ordered relationship sets. MergeAppend merges subquery results in a way that preserves the sort order. It can be used to merge sorted rows in a table partition. Therefore, different from common Append, MergeAppend needs to ensure that the input m_plan is ordered before performing operations. Generally, a sort operator appears before the MergeAppend operation (that is, in the subtree of the execution plan).
Typical Scenarios
The partition scan path is index or index-only, the partition pruning result is greater than 1, and the following conditions are met:
All partition indexes are valid B-tree indexes. The SQL query contains the LIMIT clause. During partition scan, no partitioned table query statement with the filter exists.
The MergeAppend path is no longer generated when the GUC parameter sql_beta_feature is set to 'disable_merge_append_partition'.
Examples
-- Prepare data. gaussdb=#CREATE TABLE test_range_pt (a INT, b INT, c INT) DISTRIBUTE BY REPLICATION PARTITION BY RANGE(a) ( PARTITION p1 VALUES LESS THAN (2000), PARTITION p2 VALUES LESS THAN (3000), PARTITION p3 VALUES LESS THAN (4000), PARTITION p4 VALUES LESS THAN (5000), PARTITION p5 VALUES LESS THAN (MAXVALUE) )ENABLE ROW MOVEMENT; CREATE TABLE gaussdb=#INSERT INTO test_range_pt VALUES (generate_series(1,10000),generate_series(1,10000),generate_series(1,10000)); INSERT 0 10000 gaussdb=#CREATE INDEX idx_range_b ON test_range_pt(b) GLOBAL; CREATE INDEX gaussdb=#ANALYZE test_range_pt; ANALYZE -- Execution result. gaussdb=# EXPLAIN SELECT * FROM test_range_pt UNION ALL SELECT * FROM test_range_pt order by b limit 10; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------- Data Node Scan (cost=0.00..0.00 rows=0 width=0) Node/s: dn_6002 Remote SQL: SELECT test_range_pt.a, test_range_pt.b, test_range_pt.c FROM public.test_range_pt UNION ALL SELECT test_range_pt.a, test_range_pt.b, test_range_pt.c FROM public.test_range_pt ORDER BY 2 LIMIT 10 Datanode Name: dn_6002 Limit (cost=0.01..0.49 rows=10 width=12) -> Result (cost=0.01..964.51 rows=10 width=12) -> Merge Append (cost=0.01..964.51 rows=10 width=12) Sort Key: public.test_range_pt.b -> Index Scan using idx_range_b on test_range_pt (cost=0.00..357.25 rows=10000 width=12) -> Index Scan using idx_range_b on test_range_pt (cost=0.00..357.25 rows=10000 width=12) (12 rows) -- Drop. gaussdb=#DROP TABLE test_range_pt;
In the preceding example, the output of the MergeAppend operator is as follows.
Item |
Description |
---|---|
Merge Append |
Operator name. |
Sort Key |
Keyword based on which the sort operator uses for sorting. In the example, the value is grade. |
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