Skip to content

Commit

Permalink
Make sure that pg_qualstats_index_advisor always returns arrays
Browse files Browse the repository at this point in the history
Thanks to github user romanstingler for the report.
  • Loading branch information
rjuju committed Aug 23, 2022
1 parent 66b3037 commit c0b6ca0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
* github user suprimex
* github user RekGRpth
* Zhihong Yu
* github user romanstingler
16 changes: 16 additions & 0 deletions expected/pg_qualstats.out
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,23 @@ FROM "PGQS".pg_qualstats() GROUP BY 1 ORDER BY 2 DESC;
OR-ed | 1
(2 rows)

----------------
-- index advisor
----------------
-- check that empty arrays are returned rather than NULL values
SELECT "PGQS".pg_qualstats_reset();
pg_qualstats_reset
--------------------

(1 row)

SELECT * FROM "PGQS".pg_qualstats_index_advisor(50);
pg_qualstats_index_advisor
--------------------------------------
{"indexes" : [], "unoptimised" : []}
(1 row)

-- Test some naive scenario
CREATE TABLE adv (id1 integer, id2 integer, id3 integer, val text);
INSERT INTO adv SELECT i, i, i, 'line ' || i from generate_series(1, 1000) i;
SELECT "PGQS".pg_qualstats_reset();
Expand Down
4 changes: 2 additions & 2 deletions pg_qualstats--2.0.4--2.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ CREATE OR REPLACE FUNCTION @[email protected]_qualstats_index_advisor (
AS $_$
DECLARE
v_processed bigint[] = '{}';
v_indexes json[];
v_unoptimised json[];
v_indexes json[] = '{}';
v_unoptimised json[] = '{}';

rec record;
v_nb_processed integer = 1;
Expand Down
4 changes: 2 additions & 2 deletions pg_qualstats--2.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ CREATE OR REPLACE FUNCTION @[email protected]_qualstats_index_advisor (
AS $_$
DECLARE
v_processed bigint[] = '{}';
v_indexes json[];
v_unoptimised json[];
v_indexes json[] = '{}';
v_unoptimised json[] = '{}';

rec record;
v_nb_processed integer = 1;
Expand Down
7 changes: 7 additions & 0 deletions test/sql/pg_qualstats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ SELECT COUNT(*) FROM pgqs WHERE (id = 1) OR (id > 10 AND id < 20);
SELECT CASE WHEN qualid IS NULL THEN 'OR-ed' ELSE 'AND-ed' END kind, COUNT(*)
FROM "PGQS".pg_qualstats() GROUP BY 1 ORDER BY 2 DESC;

----------------
-- index advisor
----------------

-- check that empty arrays are returned rather than NULL values
SELECT "PGQS".pg_qualstats_reset();
SELECT * FROM "PGQS".pg_qualstats_index_advisor(50);
-- Test some naive scenario
CREATE TABLE adv (id1 integer, id2 integer, id3 integer, val text);
INSERT INTO adv SELECT i, i, i, 'line ' || i from generate_series(1, 1000) i;
SELECT "PGQS".pg_qualstats_reset();
Expand Down

0 comments on commit c0b6ca0

Please sign in to comment.