Skip to content

Commit

Permalink
Merge pull request #7 from adjust/pg16-compability
Browse files Browse the repository at this point in the history
Update base62.h for pg16 compatibility
  • Loading branch information
ridvankorkmaz authored Mar 1, 2024
2 parents 0be057e + ae453bc commit 59a27bc
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/base62.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "fmgr.h"

#include "utils/builtins.h"
#if PG_VERSION_NUM >= 160000
#include "varatt.h"
#endif

PG_MODULE_MAGIC;

Expand Down
10 changes: 10 additions & 0 deletions src/base62.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

#include "postgres.h"

// @rapimo's note from ipath, we need same here, otherwise impossible to compile for PG16
/*
* pg >= 16 reorganized the toastable header files
* https://github.com/postgres/postgres/commit/d952373a987bad331c0e499463159dd142ced1ef
* to ensure cross version compatibility we do a bit of a hack here
*/
#ifndef SET_VARSIZE
#include "varatt.h"
#endif

typedef int32 base62;
typedef int64 bigbase62;
typedef int128 hugebase62;
Expand Down
3 changes: 3 additions & 0 deletions src/bigbase62.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "fmgr.h"

#include "utils/builtins.h"
#if PG_VERSION_NUM >= 160000
#include "varatt.h"
#endif

#define BIGBASE62_LENGTH 11

Expand Down
3 changes: 3 additions & 0 deletions src/hugebase62.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "libpq/pqformat.h"
#include "utils/builtins.h"

#if PG_VERSION_NUM >= 160000
#include "varatt.h"
#endif
#if PG_VERSION_NUM >= 130000
#include "common/hashfn.h"
#elif PG_VERSION_NUM >= 120000
Expand Down
30 changes: 15 additions & 15 deletions test/expected/003_hugebase.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ select '1W'::hugebase62;
(1 row)

select '3caaaaaaaaaaaaa'::hugebase62;
hugebase62
-----------------
3caaaaaaaaaaaaa
hugebase62
------------
1hwqdA
(1 row)

select '2LKcb1'::hugebase62;
Expand All @@ -41,27 +41,27 @@ select '2lkcb1'::hugebase62::bytea;
(1 row)

select 'AzL8n0Y58m7aa'::hugebase62;
hugebase62
---------------
AzL8n0Y58m7aa
hugebase62
------------
PQ
(1 row)

select 'azl8n0y58m7aa'::hugebase62;
hugebase62
---------------
azl8n0y58m7aa
hugebase62
------------
1Xitse
(1 row)

select 'AAAAAAAAAAAAAAAAAAAA'::hugebase62;
hugebase62
----------------------
AAAAAAAAAAAAAAAAAAAA
hugebase62
------------
L9gxq
(1 row)

select 'aaaaaaaaaaaaaaaaaaaa'::hugebase62;
hugebase62
----------------------
aaaaaaaaaaaaaaaaaaaa
hugebase62
------------
1aEeRQ
(1 row)

-- ERROR: out of range
Expand Down
9 changes: 8 additions & 1 deletion test/expected/004_parallel.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
set max_parallel_workers_per_gather=4;
set force_parallel_mode=on;
DO $$
BEGIN
IF current_setting('server_version_num')::int >= 160000 THEN
EXECUTE 'SET debug_parallel_query = on';
ELSE
EXECUTE 'SET force_parallel_mode = on';
END IF;
END $$;
set parallel_setup_cost = 10;
set parallel_tuple_cost = 0.001;
create table parallel_test(i int, b1 base62, b2 bigbase62, b3 hugebase62) with (parallel_workers = 4);
Expand Down
9 changes: 8 additions & 1 deletion test/expected/004_parallel_1.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
set max_parallel_workers_per_gather=4;
set force_parallel_mode=on;
DO $$
BEGIN
IF current_setting('server_version_num')::int >= 160000 THEN
EXECUTE 'SET debug_parallel_query = on';
ELSE
EXECUTE 'SET force_parallel_mode = on';
END IF;
END $$;
set parallel_setup_cost = 10;
set parallel_tuple_cost = 0.001;
create table parallel_test(i int, b1 base62, b2 bigbase62, b3 hugebase62) with (parallel_workers = 4);
Expand Down
9 changes: 8 additions & 1 deletion test/sql/004_parallel.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
set max_parallel_workers_per_gather=4;
set force_parallel_mode=on;
DO $$
BEGIN
IF current_setting('server_version_num')::int >= 160000 THEN
EXECUTE 'SET debug_parallel_query = on';
ELSE
EXECUTE 'SET force_parallel_mode = on';
END IF;
END $$;
set parallel_setup_cost = 10;
set parallel_tuple_cost = 0.001;

Expand Down

0 comments on commit 59a27bc

Please sign in to comment.