hypopg icon indicating copy to clipboard operation
hypopg copied to clipboard

Correctly allocate hypoIndex entries

Open tedyu opened this issue 1 year ago • 2 comments

ncolumns field is calculated as:

      entry->ncolumns = nkeycolumns + ninccolumns;

In hypo_injectHypotheticalIndex:

			for (i = 0; i < ncolumns; i++)
			{
				index->sortopfamily[i] = entry->sortopfamily[i];
				index->reverse_sort[i] = entry->reverse_sort[i];
				index->nulls_first[i] = entry->nulls_first[i];

However, when these fields are initialized, only nkeycolumns elements are allocated.

This PR changes the element count in allocations so that enough memory is allocated.

tedyu avatar Sep 17 '22 13:09 tedyu

cc @rjuju

tedyu avatar Sep 17 '22 13:09 tedyu

Hi,

Thanks for the report! However I think your proposed fix is backward: those info are only needed for key columns, so the loop should be changed instead. I found a few other similar mistakes, and while at it reordered the code a bit to make instructions order similar in both place, see https://github.com/HypoPG/hypopg/commit/0a80ba3090f3d291973f13b16fbb948d0b4d0ca1

rjuju avatar Sep 17 '22 14:09 rjuju