Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3824ca3

Browse files
committed
Fix pg_mcv_list deserialization
The memcpy() was copying type OIDs in the wrong direction, so thedeserialized MCV list always had them as 0. This is mostly harmlessexcept when printing the data in pg_mcv_list_items(), in which caseit reported ERROR: cache lookup failed for type 0Also added a simple regression test for pg_mcv_list_items() function,printing a single-item MCV list.Reported-By: Dean RasheedDiscussion:https://postgr.es/m/CAEZATCX6T0iDTTZrqyec4Cd6b4yuL7euu4=rQRXaVBAVrUi1Cg@mail.gmail.com
1 parent4b40e44 commit3824ca3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

‎src/backend/statistics/mcv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ statext_mcv_deserialize(bytea *data)
905905
VARSIZE_ANY(data),expected_size);
906906

907907
/* Now copy the array of type Oids. */
908-
memcpy(ptr,mcvlist->types,sizeof(Oid)*ndims);
908+
memcpy(mcvlist->types,ptr,sizeof(Oid)*ndims);
909909
ptr+= (sizeof(Oid)*ndims);
910910

911911
/* ensure alignment of the pointer (after the header fields) */

‎src/test/regress/expected/stats_ext.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,17 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND
717717
50 | 50
718718
(1 row)
719719

720+
-- test pg_mcv_list_items with a very simple (single item) MCV list
721+
TRUNCATE mcv_lists;
722+
INSERT INTO mcv_lists (a, b, c) SELECT 1, 2, 3 FROM generate_series(1,1000) s(i);
723+
ANALYZE mcv_lists;
724+
SELECT m.* FROM pg_statistic_ext,
725+
pg_mcv_list_items(stxmcv) m WHERE stxname = 'mcv_lists_stats';
726+
index | values | nulls | frequency | base_frequency
727+
-------+-----------+---------+-----------+----------------
728+
0 | {1, 2, 3} | {f,f,f} | 1 | 1
729+
(1 row)
730+
720731
RESET random_page_cost;
721732
-- mcv with arrays
722733
CREATE TABLE mcv_lists_arrays (

‎src/test/regress/sql/stats_ext.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,14 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND
411411

412412
SELECT*FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL AND c IS NULL');
413413

414+
-- test pg_mcv_list_items with a very simple (single item) MCV list
415+
TRUNCATE mcv_lists;
416+
INSERT INTO mcv_lists (a, b, c)SELECT1,2,3FROM generate_series(1,1000) s(i);
417+
ANALYZE mcv_lists;
418+
419+
SELECT m.*FROM pg_statistic_ext,
420+
pg_mcv_list_items(stxmcv) mWHERE stxname='mcv_lists_stats';
421+
414422
RESET random_page_cost;
415423

416424
-- mcv with arrays

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp