Thread: Multivariate MCV lists -- pg_mcv_list_items() seems to be broken
I just noticed the following: CREATE TABLE foo (a int, b int); INSERT INTO foo SELECT x/10, x/100 FROM generate_series(1, 100) x; CREATE STATISTICS foo_s ON a,b FROM foo; ANALYSE foo; SELECT pg_mcv_list_items(stxmcv) from pg_statistic_ext WHERE stxname = 'foo_s'; which fails with ERROR: cache lookup failed for type 0 That definitely used to work, so I'm guessing it got broken by the recent reworking of the serialisation code, but I've not looked into it. There should probably be regression test coverage of that function. Regards, Dean
On Mon, Apr 15, 2019 at 05:02:43PM +0100, Dean Rasheed wrote: >I just noticed the following: > >CREATE TABLE foo (a int, b int); >INSERT INTO foo SELECT x/10, x/100 FROM generate_series(1, 100) x; >CREATE STATISTICS foo_s ON a,b FROM foo; >ANALYSE foo; > >SELECT pg_mcv_list_items(stxmcv) from pg_statistic_ext WHERE stxname = 'foo_s'; > >which fails with > >ERROR: cache lookup failed for type 0 > >That definitely used to work, so I'm guessing it got broken by the >recent reworking of the serialisation code, but I've not looked into >it. > Yeah, that seems like a bug. I'll take a look. >There should probably be regression test coverage of that function. > Agreed. I plan to rework the existing tests to use the same approach as the MCV, so I'll add a test for this function too. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Dean Rasheed <dean.a.rasheed@gmail.com> writes: > SELECT pg_mcv_list_items(stxmcv) from pg_statistic_ext WHERE stxname = 'foo_s'; > which fails with > ERROR: cache lookup failed for type 0 > That definitely used to work, so I'm guessing it got broken by the > recent reworking of the serialisation code, but I've not looked into > it. Yeah, looks like sloppy thinking about whether or not the types array participates in maxalign-forcing? > There should probably be regression test coverage of that function. +1 regards, tom lane
On Mon, Apr 15, 2019 at 12:26:02PM -0400, Tom Lane wrote: >Dean Rasheed <dean.a.rasheed@gmail.com> writes: >> SELECT pg_mcv_list_items(stxmcv) from pg_statistic_ext WHERE stxname = 'foo_s'; >> which fails with >> ERROR: cache lookup failed for type 0 > >> That definitely used to work, so I'm guessing it got broken by the >> recent reworking of the serialisation code, but I've not looked into >> it. > >Yeah, looks like sloppy thinking about whether or not the types array >participates in maxalign-forcing? > Actually, no. It seems aligned just fine, AFAICS. The bug a bit more embarassing - the deserialization does memcpy(ptr, mcvlist->types, sizeof(Oid) * ndims); while it should be doing memcpy(mcvlist->types, ptr, sizeof(Oid) * ndims); Will fix. cheers -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services