-
Notifications
You must be signed in to change notification settings - Fork 203
Fix assertion failure in getNdvBySegHeapTuple for empty partitions. #1599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -759,17 +759,38 @@ getNdvBySegHeapTuple(AttStatsSlot * *ndvbsSlots, HeapTuple *heaptupleStats, floa | |
| (void) get_attstatsslot(ndvbsSlots[i], heaptupleStats[i], | ||
| STATISTIC_KIND_NDV_BY_SEGMENTS, InvalidOid, ATTSTATSSLOT_VALUES); | ||
|
|
||
| if ((InvalidOid != ndvbsSlots[i]->valuetype && // result is not empty | ||
| // not empty partition with invalid ndvbs | ||
| (relTuples[i] > 0 && DatumGetFloat8(ndvbsSlots[i]->values[0]) == 0)) || | ||
| // not empty partition without ndvbs | ||
| (InvalidOid == ndvbsSlots[i]->valuetype && relTuples[i] > 0)) { | ||
| if (ndvbsSlots[i]->valuetype != FLOAT8OID) | ||
| { | ||
| /* | ||
| * NDV_BY_SEGMENTS slot not found or has unexpected type. | ||
| * Non-empty partitions must have valid NDV_BY_SEGMENTS; | ||
| * empty partitions (relTuples == 0) can be skipped. | ||
| */ | ||
| if (relTuples[i] > 0) | ||
| { | ||
| valid = false; | ||
| break; | ||
| } | ||
| free_attstatsslot(ndvbsSlots[i]); | ||
| pfree(ndvbsSlots[i]); | ||
| ndvbsSlots[i] = NULL; | ||
| continue; | ||
| } | ||
|
|
||
| Assert(ndvbsSlots[i]->valuetype == FLOAT8OID); | ||
|
|
||
| if (ndvbsSlots[i]->nvalues != 1) | ||
| { | ||
| valid = false; | ||
| break; | ||
| } | ||
|
|
||
zhangwenchao-123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Assert(ndvbsSlots[i]->valuetype == FLOAT8OID); | ||
zhangwenchao-123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Assert(ndvbsSlots[i]->nvalues == 1); | ||
| /* Non-empty partition with zero NDV is suspicious */ | ||
| if (relTuples[i] > 0 && DatumGetFloat8(ndvbsSlots[i]->values[0]) == 0) | ||
| { | ||
| valid = false; | ||
| break; | ||
| } | ||
| } | ||
| return valid; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the ndvbsSlots could be release if the valid becomes false. On the other side, the ndvbsSlots and its pointer array could be also freed in aggregate_leaf_partition_ndvbs no matter it's valid or not.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, |
||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.