Tuesday, 16 June 2020

Проблема построения шардинга на базе postgres_fdw + partitioning

Как контролировать изменение foreign-партиций?
Например, если попытаться удалить столбец из локальной партиции, то получим ошибку:
ERROR:  cannot drop inherited column "a"
Таблица защищена механизмом наследования.
Однако можно безнаказанно модифицировать foreign-партиции. Никакого запрета нет и уведомления на наш сервер не придет.
И это принципиальный момент. Можно было бы создавать некоторый constraint на foreign-сервере и запрещать DDL и DML на таблицы, объявленные как foreign. Но это противоречит идеологии FDW.

Thursday, 5 September 2019

How AQO accelerates queries execution over constant dataset in PostgreSQL 11

AQO extension implements simple query-driven technique, based on machine learning concepts. AQO (Adaptive Query Optimization) extension give to the postgres planner cardinality estimations based on results of previous executions.
To see the effect of using the extension I run PostgreSQL on the Join Order Benchmark (JOB) dataset.
postgresql.conf custom options:
shared_preload_libraries = 'aqo'
aqo.mode = 'intelligent'
min_parallel_table_scan_size = 0
min_parallel_index_scan_size = 0

Training. The extension does not require a separate training stage. In the intelligent mode AQO analyses the result of completed query and trains the core of machine learning on the fly. But before measurements of query execution time I run each of the 113 JOB queries ten times.
The test results are shown in the graph below. Here tvnl denotes execution time of PostgreSQL with disabled AQO extension; tAQO denotes execution time with enabled AQO extension after training.
Profit of using the AQO extension with JOB benchmark.
As you can see, for most queries, execution time does not changed significantly. But for some queries execution time was significantly improved up to 7 times.
Using AQO with one query, 27c.sql, lead to worsen execution time. This is a special case of zero-result queries, where most query plan nodes are never visited during execution.

APPENDIX / Source data for the graph plotting /


Q    NUM    T_AQO    T_Postgres
10a    0    3047.964    3430.02
10b    1    3123.598    3179.84
10c    2    3952.579    5177.74
11a    3    185.581    186.355
11b    4    190.632    189.834
11c    5    902.906    1151.62
11d    6    1238.200    1010.16
12a    7    1846.220    1907.61
12b    8    2159.607    2149.59
12c    9    2584.313    2467.22
13a    10    3425.592    13392.8
13b    11    2564.553    7066.38
13c    12    2398.882    6931.79
13d    13    4803.911    13222.8
14a    14    3325.901    3611.1
14b    15    3153.541    3408.28
14c    16    3344.103    3657.21
15a    17    2055.251    2882.28
15b    18    2027.138    2869.4
15c    19    2178.983    3249.46
15d    20    2158.447    2496.46
16a    21    4958.791    5005.25
16b    22    8797.188    15509.7
16c    23    6456.344    6563.71
16d    24    6152.138    7095.07
17a    25    6573.176    13533.4
17b    26    5427.022    12504.8
17c    27    5085.669    8753.09
17d    28    7380.981    15794.5
17e    29    12522.292    18046
17f    30    9647.796    16315.2
18a    31    5274.107    6395.87
18b    32    1046.589    1048.37
18c    33    5983.287    5906.48
19a    34    5509.982    5711.9
19b    35    4491.611    4672.91
19c    36    5850.636    5841.47
19d    37    15762.021    24915.2
1a    38    714.301    881.801
1b    39    775.915    829.196
1c    40    702.027    733.333
1d    41    823.057    808.865
20a    42    7040.795    8785.93
20b    43    7034.773    8939.93
20c    44    7674.179    8243.65
21a    45    190.495    187.139
21b    46    194.246    192.845
21c    47    198.667    191.696
22a    48    3033.596    3388.09
22b    49    2867.397    3219.5
22c    50    3911.358    4347.19
22d    51    3732.754    4305.98
23a    52    2084.516    2025.77
23b    53    2059.473    2031.27
23c    54    2047.651    2029.73
24a    55    5480.825    6076.99
24b    56    5455.174    5658.14
25a    57    5216.836    5264.42
25b    58    4963.225    5256.14
25c    59    6166.816    6320.77
26a    60    5826.042    5159.64
26b    61    4569.123    4694.36
26c    62    8460.978    9437.04
27a    63    3373.726    2942
27b    64    380.662    2653.33
27c    65    1024.958    266.015
28a    66    8086.565    20520.1
28b    67    4028.662    4759.55
28c    68    10252.804    28447.8
29a    69    5708.451    10240.8
29b    70    5664.102    7251.11
29c    71    6836.721    34445.7
2a    72    908.747    1301.75
2b    73    870.858    1300.69
2c    74    809.473    1274.95
2d    75    1101.097    1467.81
30a    76    5634.603    6064.64
30b    77    5227.344    5600.29
30c    78    6013.770    7528.07
31a    79    5427.108    6528.47
31b    80    5533.151    5839.53
31c    81    6051.344    8001.36
32a    82    501.168    496.201
32b    83    556.861    626.015
33a    84    879.179    1352.47
33b    85    886.257    1334.02
33c    86    934.128    925.814
3a    87    2637.194    2732.59
3b    88    1660.194    1780.53
3c    89    2938.747    3064.86
4a    90    789.354    918.378
4b    91    632.061    626.059
4c    92    833.223    978.086
5a    93    268.318    266.538
5b    94    262.707    260.32
5c    95    2702.237    2726.5
6a    96    4359.613    4366.78
6b    97    4533.386    4538.49
6c    98    4394.871    4382.25
6d    99    4675.485    7544.69
6e    100    4358.768    4365.98
6f    101    6770.392    7652.4
7a    102    4199.691    4199.58
7b    103    4241.955    4205.46
7c    104    7154.836    6700.09
8a    105    2755.243    3514.36
8b    106    2732.552    2791.92
8c    107    9666.434    9683.83
8d    108    7187.340    7378.86
9a    109    3866.360    4012.08
9b    110    2985.638    3021.7
9c    111    4377.159    4784.95
9d    112    5603.785    6991.24