Skip to content

Commit

Permalink
Fix extension scripts to support all possible upgrade paths
Browse files Browse the repository at this point in the history
This commit fixes and extends the extension SQL scripts in a few ways,
to allow upgrades from all the possible versions down where the origin
is based on PostgreSQL 10, which is the oldest version supported by
pg_hint_plan currently.

PostgreSQL allows since v10 the maintenance of an extension using as
base script the oldest version supported in combination of incremental
scripts.  A full set of upgrade scripts is added by this commit,
considering v10 as the oldest path supported.  As origin versions
may have a partial schema created for the hint table with partial
definitions, the correct rules are enforced for each version when it
comes to extension dumps and GRANT rules.  The schema for the hint table
is only created in the base script.

Regression tests are added to cover all these upgrade paths.  DATA in
the Makefile is changed to hardcode all the SQL scripts that need to be
installed.

Per pull request yugabyte#111 and issues yugabyte#110 and yugabyte#60.

Backpatch-through: 10
  • Loading branch information
michaelpq committed Dec 19, 2022
1 parent 7c03155 commit 575288f
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 4 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
MODULES = pg_hint_plan
HINTPLANVER = 1.5

REGRESS = init base_plan pg_hint_plan ut-init ut-A ut-S ut-J ut-L ut-G ut-R ut-fdw ut-W ut-T ut-fini hints_anywhere
REGRESS = init base_plan pg_hint_plan ut-init ut-A ut-S ut-J ut-L ut-G ut-R \
ut-fdw ut-W ut-T ut-fini hints_anywhere oldextversions
REGRESS_OPTS = --encoding=UTF8

EXTENSION = pg_hint_plan
DATA = pg_hint_plan--*.sql
DATA = \
pg_hint_plan--1.3.0.sql \
pg_hint_plan--1.3.0--1.3.1.sql \
pg_hint_plan--1.3.1--1.3.2.sql \
pg_hint_plan--1.3.2--1.3.3.sql \
pg_hint_plan--1.3.3--1.3.4.sql \
pg_hint_plan--1.3.5--1.3.6.sql \
pg_hint_plan--1.3.4--1.3.5.sql \
pg_hint_plan--1.3.6--1.3.7.sql \
pg_hint_plan--1.3.7--1.4.sql \
pg_hint_plan--1.4--1.5.sql

EXTRA_CLEAN = RPMS

Expand Down
94 changes: 94 additions & 0 deletions expected/oldextversions.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
--
-- tests for upgrade paths
--
CREATE EXTENSION pg_hint_plan VERSION "1.3.0";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.1";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.2";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.3";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.4";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.5";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.6";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.7";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.4";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

ALTER EXTENSION pg_hint_plan UPDATE TO "1.5";
\dx+ pg_hint_plan
Objects in extension "pg_hint_plan"
Object description
---------------------------------
sequence hint_plan.hints_id_seq
table hint_plan.hints
(2 rows)

DROP EXTENSION pg_hint_plan;
1 change: 1 addition & 0 deletions expected/ut-fini.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
DROP ROLE IF EXISTS regress_super_user;
DROP ROLE IF EXISTS regress_normal_user;
DROP EXTENSION pg_hint_plan;
10 changes: 10 additions & 0 deletions pg_hint_plan--1.3.0--1.3.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.3.0--1.3.1.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.3.1'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
4 changes: 2 additions & 2 deletions pg_hint_plan--1.5.sql → pg_hint_plan--1.3.0.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* pg_hint_plan/pg_hint_plan--1.5.sql */
/* pg_hint_plan/pg_hint_plan--1.3.0.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_hint_plan" to load this file. \quit
Expand All @@ -11,7 +11,7 @@ CREATE TABLE hint_plan.hints (
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX hints_norm_and_app ON hint_plan.hints (
norm_query_string,
norm_query_string,
application_name
);

Expand Down
10 changes: 10 additions & 0 deletions pg_hint_plan--1.3.1--1.3.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.3.1--1.3.2.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.3.2'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
10 changes: 10 additions & 0 deletions pg_hint_plan--1.3.2--1.3.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.3.2--1.3.3.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.3.3'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
10 changes: 10 additions & 0 deletions pg_hint_plan--1.3.3--1.3.4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.3.3--1.3.4.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.3.4'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
10 changes: 10 additions & 0 deletions pg_hint_plan--1.3.4--1.3.5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.3.4--1.3.5.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.3.5'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
10 changes: 10 additions & 0 deletions pg_hint_plan--1.3.5--1.3.6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.3.5--1.3.6.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.3.6'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
10 changes: 10 additions & 0 deletions pg_hint_plan--1.3.6--1.3.7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.3.6--1.3.7.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.3.7'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
10 changes: 10 additions & 0 deletions pg_hint_plan--1.3.7--1.4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.3.7--1.4.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.4'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
10 changes: 10 additions & 0 deletions pg_hint_plan--1.4--1.5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* pg_hint_plan/pg_hint_plan--1.4--1.5.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION pg_dbms_stats UPDATE TO '1.5'" to load this file. \quit

SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints','');
SELECT pg_catalog.pg_extension_config_dump('hint_plan.hints_id_seq','');

GRANT SELECT ON hint_plan.hints TO PUBLIC;
GRANT USAGE ON SCHEMA hint_plan TO PUBLIC;
25 changes: 25 additions & 0 deletions sql/oldextversions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--
-- tests for upgrade paths
--

CREATE EXTENSION pg_hint_plan VERSION "1.3.0";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.1";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.2";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.3";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.4";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.5";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.6";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.3.7";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.4";
\dx+ pg_hint_plan
ALTER EXTENSION pg_hint_plan UPDATE TO "1.5";
\dx+ pg_hint_plan
DROP EXTENSION pg_hint_plan;
1 change: 1 addition & 0 deletions sql/ut-fini.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
DROP ROLE IF EXISTS regress_super_user;
DROP ROLE IF EXISTS regress_normal_user;
DROP EXTENSION pg_hint_plan;

0 comments on commit 575288f

Please sign in to comment.