forked from greenplum-db/gpdb-archive
-
Notifications
You must be signed in to change notification settings - Fork 23
ADBDEV-7771: Fix incorrect behavior of gp_percentile_* functions #1928
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mos65o2
pushed a commit
that referenced
this pull request
Jul 18, 2025
Commit b90f952 added five GPDB-specific functions gp_percentile_cont_float8_transition, gp_percentile_cont_interval_transition, gp_percentile_cont_timestamp_transition, gp_percentile_cont_timestamptz_transition and gp_percentile_disc_transition. 1) All these five functions use five arguments internally in the C implementation, but they were added to the catalog in the file src/include/catalog/pg_proc.dat with four arguments, which could lead to incorrect results, assertions when freeing a null pointer and even segfaults when dereferencing a null pointer. This patch adds the missing arguments. 2) All these five functions under certain conditions can return their first argument, but if the first argument was NULL (and the NULL argument is passed with the additional isnull flag), then when it was returned, all these five functions lost the additional isnull flag, which could also lead to incorrect results (for the non-varlena types of the first two arguments), and to assertions when freeing a null pointer and even segfaults when dereferencing a null pointer (for the varlena types). This patch adds saving of the additional isnull flag, and now under the same conditions, all these five functions return NULL. The patch adds three tests for each of the five functions. Ticket: ADBDEV-7771 (cherry picked from commit 477b04a)
RekGRpth
reviewed
Jul 18, 2025
RekGRpth
reviewed
Jul 24, 2025
mos65o2
added a commit
that referenced
this pull request
Jul 24, 2025
…1928) The signature of the gp_percentile_cont_transition and gp_percentile_disc_transition functions in pg_proc.dat did not match the number of arguments they processed (they are called from gp_percentile_*_* functions). This led to an incorrect result or segfault when calling these functions directly, since the number of arguments passed was less than the number processed. This commit adds a check for matching the number of input arguments - there must be 5. Since the number of arguments in pg_proc.dat is 4, direct calls to these functions return an error. This change does not affect 'percentile_* WITHIN GROUP' queries with the ORCA optimizer.
This comment was marked as resolved.
This comment was marked as resolved.
mos65o2
pushed a commit
that referenced
this pull request
Jul 25, 2025
Commit b90f952 added five GPDB-specific functions gp_percentile_cont_float8_transition, gp_percentile_cont_interval_transition, gp_percentile_cont_timestamp_transition, gp_percentile_cont_timestamptz_transition and gp_percentile_disc_transition. 1) All these five functions use five arguments internally in the C implementation, but they were added to the catalog in the file src/include/catalog/pg_proc.dat with four arguments, which could lead to incorrect results, assertions when freeing a null pointer and even segfaults when dereferencing a null pointer. This patch adds the missing arguments. 2) All these five functions under certain conditions can return their first argument, but if the first argument was NULL (and the NULL argument is passed with the additional isnull flag), then when it was returned, all these five functions lost the additional isnull flag, which could also lead to incorrect results (for the non-varlena types of the first two arguments), and to assertions when freeing a null pointer and even segfaults when dereferencing a null pointer (for the varlena types). This patch adds saving of the additional isnull flag, and now under the same conditions, all these five functions return NULL. The patch adds three tests for each of the five functions. (cherry picked from commit 477b04a) Changes in original commit: - pg_proc.dat is not changed. - added check in gp_percentile_*_* functions. - test is adapted. Because changes to pg_proc.dat cause difficulties with cluster upgrades, this file is left as is. However, in this case, the signature of the gp_percentile_cont_transition and gp_percentile_disc_transition functions in pg_proc.dat did not match the number of arguments they processed (they are called from gp_percentile_*_* functions). This led to an incorrect result or segfault when calling these functions directly, since the number of arguments passed was less than the number processed. So, we add check for matching the number of input arguments (there must be 5). Now, direct calls to these functions return an error. This change does not affect 'percentile_* WITHIN GROUP' queries with the ORCA optimizer. Ticket: ADBDEV-7771
bf4a570 to
cf19209
Compare
mos65o2
pushed a commit
that referenced
this pull request
Jul 25, 2025
Commit b90f952 added five GPDB-specific functions gp_percentile_cont_float8_transition, gp_percentile_cont_interval_transition, gp_percentile_cont_timestamp_transition, gp_percentile_cont_timestamptz_transition and gp_percentile_disc_transition. 1) All these five functions use five arguments internally in the C implementation, but they were added to the catalog in the file src/include/catalog/pg_proc.dat with four arguments, which could lead to incorrect results, assertions when freeing a null pointer and even segfaults when dereferencing a null pointer. This patch adds the missing arguments. 2) All these five functions under certain conditions can return their first argument, but if the first argument was NULL (and the NULL argument is passed with the additional isnull flag), then when it was returned, all these five functions lost the additional isnull flag, which could also lead to incorrect results (for the non-varlena types of the first two arguments), and to assertions when freeing a null pointer and even segfaults when dereferencing a null pointer (for the varlena types). This patch adds saving of the additional isnull flag, and now under the same conditions, all these five functions return NULL. The patch adds three tests for each of the five functions. (cherry picked from commit 477b04a) Changes in original commit: - pg_proc.dat is not changed. - added check in gp_percentile_*_transition functions. - test is adapted. Because changes to pg_proc.dat cause difficulties with cluster upgrades, this file is left as is. However, in this case, the signature of the gp_percentile_cont_transition and gp_percentile_disc_transition functions in pg_proc.dat did not match the number of arguments they processed (they are called from gp_percentile_*_* functions). This led to an incorrect result or segfault when calling these functions directly, since the number of arguments passed was less than the number processed. So, we add check for matching the number of input arguments (there must be 5). Now, direct calls to these functions return an error. This change does not affect 'percentile_* WITHIN GROUP' queries with the ORCA optimizer. Ticket: ADBDEV-7771
Author
Is it ok? |
This comment was marked as resolved.
This comment was marked as resolved.
RekGRpth
reviewed
Jul 25, 2025
RekGRpth
reviewed
Jul 25, 2025
mos65o2
pushed a commit
that referenced
this pull request
Jul 25, 2025
Commit b90f952 added five GPDB-specific functions gp_percentile_cont_float8_transition, gp_percentile_cont_interval_transition, gp_percentile_cont_timestamp_transition, gp_percentile_cont_timestamptz_transition and gp_percentile_disc_transition. 1) All these five functions use five arguments internally in the C implementation, but they were added to the catalog in the file src/include/catalog/pg_proc.dat with four arguments, which could lead to incorrect results, assertions when freeing a null pointer and even segfaults when dereferencing a null pointer. This patch adds the missing arguments. 2) All these five functions under certain conditions can return their first argument, but if the first argument was NULL (and the NULL argument is passed with the additional isnull flag), then when it was returned, all these five functions lost the additional isnull flag, which could also lead to incorrect results (for the non-varlena types of the first two arguments), and to assertions when freeing a null pointer and even segfaults when dereferencing a null pointer (for the varlena types). This patch adds saving of the additional isnull flag, and now under the same conditions, all these five functions return NULL. The patch adds three tests for each of the five functions. (cherry picked from commit 477b04a) Changes in original commit: - pg_proc.dat is not changed. - added check in gp_percentile_*_transition functions. - test is adapted. Because changes to pg_proc.dat cause difficulties with cluster upgrades, this file is left as is. However, in this case, the signature of the gp_percentile_cont_transition and gp_percentile_disc_transition functions in pg_proc.dat did not match the number of arguments they processed (they are called from gp_percentile_*_* functions). This led to an incorrect result or segfault when calling these functions directly, since the number of arguments passed was less than the number processed. So, we add check for matching the number of input arguments (there must be 5). Now, direct calls to these functions return an error. This change does not affect 'percentile_* WITHIN GROUP' queries with the ORCA optimizer. Ticket: ADBDEV-7771
RekGRpth
reviewed
Jul 28, 2025
Commit b90f952 added five GPDB-specific functions gp_percentile_cont_float8_transition, gp_percentile_cont_interval_transition, gp_percentile_cont_timestamp_transition, gp_percentile_cont_timestamptz_transition and gp_percentile_disc_transition. 1) All these five functions use five arguments internally in the C implementation, but they were added to the catalog in the file src/include/catalog/pg_proc.dat with four arguments, which could lead to incorrect results, assertions when freeing a null pointer and even segfaults when dereferencing a null pointer. This patch adds the missing arguments. 2) All these five functions under certain conditions can return their first argument, but if the first argument was NULL (and the NULL argument is passed with the additional isnull flag), then when it was returned, all these five functions lost the additional isnull flag, which could also lead to incorrect results (for the non-varlena types of the first two arguments), and to assertions when freeing a null pointer and even segfaults when dereferencing a null pointer (for the varlena types). This patch adds saving of the additional isnull flag, and now under the same conditions, all these five functions return NULL. The patch adds three tests for each of the five functions. (cherry picked from commit 477b04a) Changes in original commit: - pg_proc.dat is not changed. - added check in gp_percentile_*_transition functions. - test is adapted. Because changes to pg_proc.dat cause difficulties with cluster upgrades, this file is left as is. However, in this case, the signature of the gp_percentile_cont_transition and gp_percentile_disc_transition functions in pg_proc.dat did not match the number of arguments they processed (they are called from gp_percentile_*_* functions). This led to an incorrect result or segfault when calling these functions directly, since the number of arguments passed was less than the number processed. So, we add check for matching the number of input arguments (there must be 5). Now, direct calls to these functions return an error. This change does not affect 'percentile_* WITHIN GROUP' queries with the ORCA optimizer. Ticket: ADBDEV-7771
hilltracer
approved these changes
Aug 6, 2025
RekGRpth
approved these changes
Aug 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix incorrect behavior of gp_percentile_* functions (#1928)
Commit b90f952 added five GPDB-specific functions
gp_percentile_cont_float8_transition, gp_percentile_cont_interval_transition,
gp_percentile_cont_timestamp_transition,
gp_percentile_cont_timestamptz_transition and gp_percentile_disc_transition.
All these five functions use five arguments internally in the C
implementation, but they were added to the catalog in the file
src/include/catalog/pg_proc.dat with four arguments, which could lead to
incorrect results, assertions when freeing a null pointer and even segfaults
when dereferencing a null pointer. This patch adds the missing arguments.
All these five functions under certain conditions can return their first
argument, but if the first argument was NULL (and the NULL argument is passed
with the additional isnull flag), then when it was returned, all these five
functions lost the additional isnull flag, which could also lead to incorrect
results (for the non-varlena types of the first two arguments), and to
assertions when freeing a null pointer and even segfaults when dereferencing a
null pointer (for the varlena types). This patch adds saving of the additional
isnull flag, and now under the same conditions, all these five functions return
NULL.
The patch adds three tests for each of the five functions.
(cherry picked from commit 477b04a)
Changes in original commit:
Because changes to pg_proc.dat cause difficulties with cluster upgrades, this
file is left as is. However, in this case, the signature of
the gp_percentile_cont_transition and gp_percentile_disc_transition functions
in pg_proc.dat did not match the number of arguments they processed (they are
called from gp_percentile_*_* functions). This led to an incorrect result or
segfault when calling these functions directly, since the number of arguments
passed was less than the number processed. So, we add check for matching the
number of input arguments (there must be 5). Now, direct calls to these
functions return an error.
This change does not affect 'percentile_* WITHIN GROUP' queries with the
ORCA optimizer.
Ticket: ADBDEV-7771
Commits in the PR should be merged with a rebase mode to preserve authorship.