-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle better the hint table if the extension is not created
An environment enabling pg_hint_plan.enable_hint_table while pg_hint_plan has not been created as an extension would fail all its queries as the table created by the extension does not exist. This commit adds a check at the top of get_hints_from_table() to check if the extension is installed before attempting to use the hint table, generating a WARNING. We have discussed about a few options, but a WARNING is more consistent with how duplicated hints or compute_query_id disabled are handled. This does not completely close the failure hole, though, as it is still possible to see the table lookup failure for the CREATE EXTENSION command enabling pg_hint_plan as an extension if enable_hint_table is enabled. In terms of code simplicity, I am not really convinced that we need to do more just for that. This commit relies on 490f869d92e5 that has introduced syscache entries for pg_extension. On stable branches, we will need a different logic with a check on the table itself with its namespace. Idea based on some feedback from Julien Rouhaud. The tests are from me. Author: Sami Imseih, Michael Paquier Backpatch-through: 12 Per issue #191.
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- Tests for the hint table | ||
LOAD 'pg_hint_plan'; | ||
-- Attempting to use the hint table without the extension created | ||
-- emits a WARNING. | ||
SET pg_hint_plan.enable_hint_table TO on; | ||
SELECT 1; | ||
WARNING: cannot use the hint table | ||
HINT: Run "CREATE EXTENSION pg_hint_plan" to create the hint table. | ||
?column? | ||
---------- | ||
1 | ||
(1 row) | ||
|
||
SET pg_hint_plan.enable_hint_table TO off; | ||
CREATE EXTENSION pg_hint_plan; | ||
SET pg_hint_plan.enable_hint_table TO on; | ||
SELECT 1; | ||
?column? | ||
---------- | ||
1 | ||
(1 row) | ||
|
||
SET pg_hint_plan.enable_hint_table TO off; | ||
DROP EXTENSION pg_hint_plan; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- Tests for the hint table | ||
LOAD 'pg_hint_plan'; | ||
|
||
-- Attempting to use the hint table without the extension created | ||
-- emits a WARNING. | ||
SET pg_hint_plan.enable_hint_table TO on; | ||
SELECT 1; | ||
SET pg_hint_plan.enable_hint_table TO off; | ||
|
||
CREATE EXTENSION pg_hint_plan; | ||
SET pg_hint_plan.enable_hint_table TO on; | ||
SELECT 1; | ||
SET pg_hint_plan.enable_hint_table TO off; | ||
DROP EXTENSION pg_hint_plan; |