Skip to content

Commit 73c2acc

Browse files
committed
Merge branch 'rel_future_beta' into rel_future_update_node
2 parents c58238b + bce0226 commit 73c2acc

File tree

9 files changed

+89
-38
lines changed

9 files changed

+89
-38
lines changed

META.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pg_pathman",
33
"abstract": "Partitioning tool",
44
"description": "The `pg_pathman` module provides optimized partitioning mechanism and functions to manage partitions.",
5-
"version": "1.4.1",
5+
"version": "1.4.2",
66
"maintainer": [
77
"Ildar Musin <i.musin@postgrespro.ru>",
88
"Dmitry Ivanov <d.ivanov@postgrespro.ru>",
@@ -24,7 +24,7 @@
2424
"pg_pathman": {
2525
"file": "pg_pathman--1.4.sql",
2626
"docfile": "README.md",
27-
"version": "1.4.1",
27+
"version": "1.4.2",
2828
"abstract": "Partitioning tool"
2929
}
3030
},

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ SET pg_pathman.enable = t;
102102

103103
## Available functions
104104

105+
### Module's version
106+
107+
```plpgsql
108+
pathman_version()
109+
```
110+
Although it's possible to get major and minor version numbers using `\dx pg_pathman`, it doesn't show the actual [patch number](http://semver.org/). This function returns a complete version number of the loaded pg_pathman module in `MAJOR.MINOR.PATCH` format.
111+
105112
### Partition creation
106113
```plpgsql
107114
create_hash_partitions(relation REGCLASS,
@@ -282,7 +289,7 @@ Update RANGE partitioned table interval. Note that interval must not be negative
282289
```plpgsql
283290
set_enable_parent(relation REGCLASS, value BOOLEAN)
284291
```
285-
Include/exclude parent table into/from query plan. In original PostgreSQL planner parent table is always included into query plan even if it's empty which can lead to additional overhead. You can use `disable_parent()` if you are never going to use parent table as a storage. Default value depends on the `partition_data` parameter that was specified during initial partitioning in `create_range_partitions()` or `create_partitions_from_range()` functions. If the `partition_data` parameter was `true` then all data have already been migrated to partitions and parent table disabled. Otherwise it is enabled.
292+
Include/exclude parent table into/from query plan. In original PostgreSQL planner parent table is always included into query plan even if it's empty which can lead to additional overhead. You can use `disable_parent()` if you are never going to use parent table as a storage. Default value depends on the `partition_data` parameter that was specified during initial partitioning in `create_range_partitions()` function. If the `partition_data` parameter was `true` then all data have already been migrated to partitions and parent table disabled. Otherwise it is enabled.
286293

287294
```plpgsql
288295
set_auto(relation REGCLASS, value BOOLEAN)

expected/pathman_calamity.out

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ SELECT debug_capture();
99

1010
(1 row)
1111

12-
SELECT get_pathman_lib_version();
13-
get_pathman_lib_version
14-
-------------------------
15-
10500
12+
SELECT pathman_version();
13+
pathman_version
14+
-----------------
15+
1.5.0
1616
(1 row)
1717

1818
set client_min_messages = NOTICE;

init.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,6 @@ CREATE OR REPLACE FUNCTION @extschema@.debug_capture()
870870
RETURNS VOID AS 'pg_pathman', 'debug_capture'
871871
LANGUAGE C STRICT;
872872

873-
CREATE OR REPLACE FUNCTION @extschema@.get_pathman_lib_version()
874-
RETURNS CSTRING AS 'pg_pathman', 'get_pathman_lib_version'
873+
CREATE OR REPLACE FUNCTION @extschema@.pathman_version()
874+
RETURNS CSTRING AS 'pg_pathman', 'pathman_version'
875875
LANGUAGE C STRICT;

sql/pathman_calamity.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CREATE SCHEMA calamity;
77
/* call for coverage test */
88
set client_min_messages = ERROR;
99
SELECT debug_capture();
10-
SELECT get_pathman_lib_version();
10+
SELECT pathman_version();
1111
set client_min_messages = NOTICE;
1212

1313

src/include/compat/pg_compat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
/*
210210
* create_nestloop_path()
211211
*/
212-
#if PG_VERSION_NUM >= 100000
212+
#if PG_VERSION_NUM >= 100000 || (defined(PGPRO_VERSION) && PG_VERSION_NUM >= 90603)
213213
#define create_nestloop_path_compat(root, joinrel, jointype, workspace, extra, \
214214
outer, inner, filtered_joinclauses, pathkeys, \
215215
required_outer) \

src/include/init.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ simpify_mcxt_name(MemoryContext mcxt)
153153
#define DEFAULT_PATHMAN_OVERRIDE_COPY true
154154

155155

156-
/* Lowest version of Pl/PgSQL frontend compatible with internals (0xAA_BB_CC) */
157-
#define LOWEST_COMPATIBLE_FRONT 0x010500
156+
/* Lowest version of Pl/PgSQL frontend compatible with internals */
157+
#define LOWEST_COMPATIBLE_FRONT "1.5.0"
158158

159-
/* Current version of native C library (0xAA_BB_CC) */
160-
#define CURRENT_LIB_VERSION 0x010500
159+
/* Current version of native C library */
160+
#define CURRENT_LIB_VERSION "1.5.0"
161161

162162

163163
void *pathman_cache_search_relid(HTAB *cache_table,

src/init.c

+64-20
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "utils/syscache.h"
3939
#include "utils/typcache.h"
4040

41+
#include <stdlib.h>
42+
4143

4244
/* Various memory contexts for caches */
4345
MemoryContext TopPathmanContext = NULL;
@@ -92,9 +94,10 @@ static bool read_opexpr_const(const OpExpr *opexpr,
9294

9395

9496
/* Validate SQL facade */
95-
static uint32 build_sql_facade_version(char *version_cstr);
96-
static uint32 get_sql_facade_version(void);
97-
static void validate_sql_facade_version(uint32 ver);
97+
static uint32 build_semver_uint32(char *version_cstr);
98+
static uint32 get_plpgsql_frontend_version(void);
99+
static void validate_plpgsql_frontend_version(uint32 current_ver,
100+
uint32 compatible_ver);
98101

99102

100103
/*
@@ -206,7 +209,8 @@ load_config(void)
206209
return false; /* remain 'uninitialized', exit before creating main caches */
207210

208211
/* Validate pg_pathman's Pl/PgSQL facade (might be outdated) */
209-
validate_sql_facade_version(get_sql_facade_version());
212+
validate_plpgsql_frontend_version(get_plpgsql_frontend_version(),
213+
build_semver_uint32(LOWEST_COMPATIBLE_FRONT));
210214

211215
/* Create various hash tables (caches) */
212216
init_local_cache();
@@ -1196,27 +1200,66 @@ validate_hash_constraint(const Expr *expr,
11961200

11971201
/* Parse cstring and build uint32 representing the version */
11981202
static uint32
1199-
build_sql_facade_version(char *version_cstr)
1203+
build_semver_uint32(char *version_cstr)
12001204
{
1201-
uint32 version;
1205+
uint32 version = 0;
1206+
bool expect_num_token = false;
1207+
long max_dots = 2;
1208+
char *pos = version_cstr;
1209+
1210+
while (*pos)
1211+
{
1212+
/* Invert expected token type */
1213+
expect_num_token = !expect_num_token;
1214+
1215+
if (expect_num_token)
1216+
{
1217+
char *end_pos;
1218+
long num;
1219+
long i;
1220+
1221+
/* Parse number */
1222+
num = strtol(pos, &end_pos, 10);
12021223

1203-
/* expect to see x+.y+.z+ */
1204-
version = strtol(version_cstr, &version_cstr, 10) & 0xFF;
1224+
if (pos == end_pos || num > 99 || num < 0)
1225+
goto version_error;
12051226

1206-
version <<= 8;
1207-
if (strlen(version_cstr) > 1)
1208-
version |= (strtol(version_cstr + 1, &version_cstr, 10) & 0xFF);
1227+
for (i = 0; i < max_dots; i++)
1228+
num *= 100;
12091229

1210-
version <<= 8;
1211-
if (strlen(version_cstr) > 1)
1212-
version |= (strtol(version_cstr + 1, &version_cstr, 10) & 0xFF);
1230+
version += num;
1231+
1232+
/* Move position */
1233+
pos = end_pos;
1234+
}
1235+
else
1236+
{
1237+
/* Expect to see less dots */
1238+
max_dots--;
1239+
1240+
if (*pos != '.' || max_dots < 0)
1241+
goto version_error;
1242+
1243+
/* Move position */
1244+
pos++;
1245+
}
1246+
}
1247+
1248+
if (!expect_num_token)
1249+
goto version_error;
12131250

12141251
return version;
1252+
1253+
version_error:
1254+
DisablePathman(); /* disable pg_pathman since config is broken */
1255+
ereport(ERROR, (errmsg("wrong version: \"%s\"", version_cstr),
1256+
errhint(INIT_ERROR_HINT)));
1257+
return 0; /* keep compiler happy */
12151258
}
12161259

12171260
/* Get version of pg_pathman's facade written in Pl/PgSQL */
12181261
static uint32
1219-
get_sql_facade_version(void)
1262+
get_plpgsql_frontend_version(void)
12201263
{
12211264
Relation pg_extension_rel;
12221265
ScanKeyData skey;
@@ -1255,20 +1298,21 @@ get_sql_facade_version(void)
12551298
systable_endscan(scan);
12561299
heap_close(pg_extension_rel, AccessShareLock);
12571300

1258-
return build_sql_facade_version(version_cstr);
1301+
return build_semver_uint32(version_cstr);
12591302
}
12601303

12611304
/* Check that current Pl/PgSQL facade is compatible with internals */
12621305
static void
1263-
validate_sql_facade_version(uint32 ver)
1306+
validate_plpgsql_frontend_version(uint32 current_ver, uint32 compatible_ver)
12641307
{
1265-
Assert(ver > 0);
1308+
Assert(current_ver > 0);
1309+
Assert(compatible_ver > 0);
12661310

12671311
/* Compare ver to 'lowest compatible frontend' version */
1268-
if (ver < LOWEST_COMPATIBLE_FRONT)
1312+
if (current_ver < compatible_ver)
12691313
{
12701314
elog(DEBUG1, "current version: %x, lowest compatible: %x",
1271-
ver, LOWEST_COMPATIBLE_FRONT);
1315+
current_ver, compatible_ver);
12721316

12731317
DisablePathman(); /* disable pg_pathman since config is broken */
12741318
ereport(ERROR,

src/pl_funcs.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ PG_FUNCTION_INFO_V1( invoke_on_partition_created_callback );
7070
PG_FUNCTION_INFO_V1( check_security_policy );
7171

7272
PG_FUNCTION_INFO_V1( debug_capture );
73-
PG_FUNCTION_INFO_V1( get_pathman_lib_version );
73+
PG_FUNCTION_INFO_V1( pathman_version );
7474

7575

7676
/* User context for function show_partition_list_internal() */
@@ -1120,7 +1120,7 @@ debug_capture(PG_FUNCTION_ARGS)
11201120

11211121
/* NOTE: just in case */
11221122
Datum
1123-
get_pathman_lib_version(PG_FUNCTION_ARGS)
1123+
pathman_version(PG_FUNCTION_ARGS)
11241124
{
1125-
PG_RETURN_CSTRING(psprintf("%x", CURRENT_LIB_VERSION));
1125+
PG_RETURN_CSTRING(CURRENT_LIB_VERSION);
11261126
}

0 commit comments

Comments
 (0)