PartitionedTableScan Node

Updated at: 2025-01-21 02:20

This topic describes the usage and performance of the PartitionedTableScan Node feature.

Background information

The Append operator is a commonly used but low-performance query operator for partitioned tables. To meet the requirements for query performance, PolarDB provides the PartitionedTableScan operator as a more efficient solution. The PartitionedTableScan operator is used to solve the issue of low query performance when a large number of partitions exist in a partitioned table.

Limits

  • The PolarDB for PostgreSQL (Compatible with Oracle) minor engine version must be V1.1.32 or later.

  • PartitionedTableScan only supports SELECT statements and does not support DML statements.

  • PartitionedTableScan does not support partitionwise joins. If you enable partitionwise joins, the execution plan does not contain PartitionedTableScan operators.

  • PartitionedTableScan cannot be executed in parallel.

Precautions

The PartitionedTable Scan Node feature is supported only for clusters whose minor engine version is V1.1.32 and later. If you want to enable this feature for existing clusters, contact technical support.

Usage

Create a partitioned table.

CREATE TABLE prt1 (a int, b int, c varchar) PARTITION BY Hash(a) partitions 16;

Enable the PartitionedTableScan operator by using parameters

When the number of partitions of a partitioned table is greater than the value of the polar_num_parts_for_partitionedscan parameter, the PartitionedTableScan operator is generated. Valid values of the polar_num_parts_for_partitionedscan parameter: -1 to 2147483647. Default value: 64.

Note
  • If the value of polar_num_parts_for_partitionedscan is -1, the PartitionedTableScan operator is enabled regardless of the number of partitions of the partition table.

  • If the value of polar_num_parts_for_partitionedscan is 0, the PartitionedTableScan operator is not be enabled, regardless of the number of partitions of the partition table.

Example:

SET polar_num_parts_for_partitionedscan to -1;
explain select * from prt1;
                           QUERY PLAN                            
-----------------------------------------------------------------
 PartitionedTableScan on prt1  (cost=0.00..1.00 rows=1 width=40)
   ->  Seq Scan on prt1  (cost=0.00..1.00 rows=1 width=40)
(2 rows)

Use hints

Use the hint syntax PARTEDSCAN (table alias). Example:

EXPLAIN select /*+PARTEDSCAN(prt1) */ select * from prt1;
                           QUERY PLAN                            
-----------------------------------------------------------------
 PartitionedTableScan on prt1  (cost=0.00..1.00 rows=1 width=40)
   ->  Seq Scan on prt1  (cost=0.00..1.00 rows=1 width=40)
(2 rows)

Performance tests

Compared to Append, PartitionedTableScan is more efficient. In this section, tests are conducted to compare the performance difference between PartitionedTableScan and Append.

The following SQL statements are used for testing:

explain select  * from prt1 where b = 10; 

explain select /*+PARTEDSCAN(prt1) */ * from prt1 where b = 10;  
Note

The following test results are provided only for reference. The actual results may vary based on different configurations and conditions. The tests are conducted in consistent environment configurations. The number of partitions is the only variable.

The execution duration of a single SQL statement

Number of partitions

Append

PartitionedTableScan

Number of partitions

Append

PartitionedTableScan

16

0.266ms

0.067ms

32

1.820ms

0.258ms

64

3.654ms

0.402ms

128

7.010ms

0.664ms

256

14.095ms

1.247ms

512

27.697ms

2.328ms

1024

73.176ms

4.165ms

Memory usage of a single SQL statement

Number of partitions

Append

PartitionedTableScan

Number of partitions

Append

PartitionedTableScan

16

1,170 KB

1,044 KB

32

1,240 KB

1,044 KB

64

2,120 KB

1,624 KB

128

2,244 KB

1,524 KB

256

2,888 KB

2,072 KB

512

4,720 KB

3,012 KB

1024

8,236 KB

5,280 KB

Queries per second (QPS)

pgbench -i --scale=10
pgbench -c 64 -j 64 -n -T60
Query:
	explain select  * from prt1 where b = 10; 
	explain select /*+PARTEDSCAN(prt1) */ * from prt1 where b = 10;  

Number of partitions

Append

PartitionedTableScan

Number of partitions

Append

PartitionedTableScan

16

25,318

93,950

32

10,906

61,879

64

5,281

30,839

128

2,195

16,684

256

920

8,372

512

92

3,708

1024

21

1,190

Conclusions

Based on the preceding performance tests, PartitionedTableScan shows significant performance improvement compared with Append, especially when a large number of partitions are involved. If the tables that are involved in your business have a large number of partitions, and queries require a long time to be executed, we recommend that you use PartitionedTableScan to improve the performance.

  • On this page (1, T)
  • Background information
  • Limits
  • Precautions
  • Usage
  • Enable the PartitionedTableScan operator by using parameters
  • Use hints
  • Performance tests
  • The execution duration of a single SQL statement
  • Memory usage of a single SQL statement
  • Queries per second (QPS)
  • Conclusions
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare