1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-05 09:19:17 +03:00

Fix pg_mcv_list deserialization

The memcpy() was copying type OIDs in the wrong direction, so the
deserialized MCV list always had them as 0. This is mostly harmless
except when printing the data in pg_mcv_list_items(), in which case
it reported

    ERROR:  cache lookup failed for type 0

Also added a simple regression test for pg_mcv_list_items() function,
printing a single-item MCV list.

Reported-By: Dean Rasheed
Discussion: https://postgr.es/m/CAEZATCX6T0iDTTZrqyec4Cd6b4yuL7euu4=rQRXaVBAVrUi1Cg@mail.gmail.com
This commit is contained in:
Tomas Vondra 2019-04-16 00:01:39 +02:00
parent 4b40e44f07
commit 3824ca30d1
3 changed files with 20 additions and 1 deletions

View File

@ -905,7 +905,7 @@ statext_mcv_deserialize(bytea *data)
VARSIZE_ANY(data), expected_size); VARSIZE_ANY(data), expected_size);
/* Now copy the array of type Oids. */ /* Now copy the array of type Oids. */
memcpy(ptr, mcvlist->types, sizeof(Oid) * ndims); memcpy(mcvlist->types, ptr, sizeof(Oid) * ndims);
ptr += (sizeof(Oid) * ndims); ptr += (sizeof(Oid) * ndims);
/* ensure alignment of the pointer (after the header fields) */ /* ensure alignment of the pointer (after the header fields) */

View File

@ -717,6 +717,17 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND
50 | 50 50 | 50
(1 row) (1 row)
-- test pg_mcv_list_items with a very simple (single item) MCV list
TRUNCATE mcv_lists;
INSERT INTO mcv_lists (a, b, c) SELECT 1, 2, 3 FROM generate_series(1,1000) s(i);
ANALYZE mcv_lists;
SELECT m.* FROM pg_statistic_ext,
pg_mcv_list_items(stxmcv) m WHERE stxname = 'mcv_lists_stats';
index | values | nulls | frequency | base_frequency
-------+-----------+---------+-----------+----------------
0 | {1, 2, 3} | {f,f,f} | 1 | 1
(1 row)
RESET random_page_cost; RESET random_page_cost;
-- mcv with arrays -- mcv with arrays
CREATE TABLE mcv_lists_arrays ( CREATE TABLE mcv_lists_arrays (

View File

@ -411,6 +411,14 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL AND c IS NULL'); SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL AND c IS NULL');
-- test pg_mcv_list_items with a very simple (single item) MCV list
TRUNCATE mcv_lists;
INSERT INTO mcv_lists (a, b, c) SELECT 1, 2, 3 FROM generate_series(1,1000) s(i);
ANALYZE mcv_lists;
SELECT m.* FROM pg_statistic_ext,
pg_mcv_list_items(stxmcv) m WHERE stxname = 'mcv_lists_stats';
RESET random_page_cost; RESET random_page_cost;
-- mcv with arrays -- mcv with arrays