You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "HuSen8891 (via GitHub)" <gi...@apache.org> on 2025/08/29 10:40:11 UTC
[PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
HuSen8891 opened a new pull request, #1338:
URL: https://github.com/apache/cloudberry/pull/1338
If QueryFinishPending is set when query is running into dumptuples, the tuplecontext is reset but memtuples are not cumsumed. When query is running into dumptuples again, tuplesort_sort_memtuples will access these memtuples, and the memory allocated in tuplecontext is already freed, this will cause invalid memory access.
To avoid this situation, do nothing in dumptuples if QueryFinishPending is set.
<!-- Thank you for your contribution to Apache Cloudberry (Incubating)! -->
Fixes #ISSUE_Number
### What does this PR do?
<!-- Brief overview of the changes, including any major features or fixes -->
### Type of Change
- [ ] Bug fix (non-breaking change)
- [ ] New feature (non-breaking change)
- [ ] Breaking change (fix or feature with breaking changes)
- [ ] Documentation update
### Breaking Changes
<!-- Remove if not applicable. If yes, explain impact and migration path -->
### Test Plan
<!-- How did you test these changes? -->
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Passed `make installcheck`
- [ ] Passed `make -C src/test installcheck-cbdb-parallel`
### Impact
<!-- Remove sections that don't apply -->
**Performance:**
<!-- Any performance implications? -->
**User-facing changes:**
<!-- Any changes visible to users? -->
**Dependencies:**
<!-- New dependencies or version changes? -->
### Checklist
- [ ] Followed [contribution guide](https://cloudberry.apache.org/contribute/code)
- [ ] Added/updated documentation
- [ ] Reviewed code for security implications
- [ ] Requested review from [cloudberry committers](https://github.com/orgs/apache/teams/cloudberry-committers)
### Additional Context
<!-- Any other information that would help reviewers? Remove if none -->
### CI Skip Instructions
<!--
To skip CI builds, add the appropriate CI skip identifier to your PR title.
The identifier must:
- Be in square brackets []
- Include the word "ci" and either "skip" or "no"
- Only use for documentation-only changes or when absolutely necessary
-->
---
<!-- Join our community:
- Mailing list: [dev@cloudberry.apache.org](https://lists.apache.org/list.html?dev@cloudberry.apache.org) (subscribe: dev-subscribe@cloudberry.apache.org)
- Discussions: https://github.com/apache/cloudberry/discussions -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#discussion_r2317608452
##########
src/backend/utils/sort/tuplesort.c:
##########
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
!alltuples)
return;
+ /*
+ * do nothing if we are told to finish execution.
+ */
+ if (QueryFinishPending)
Review Comment:
which caller reset tuplecontext ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#discussion_r2316188913
##########
src/backend/utils/sort/tuplesort.c:
##########
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
!alltuples)
return;
+ /*
+ * do nothing if we are told to finish execution.
+ */
+ if (QueryFinishPending)
Review Comment:
tuplecontext isReset is true ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#issuecomment-3243619212
any stack to help to review ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "HuSen8891 (via GitHub)" <gi...@apache.org>.
HuSen8891 commented on code in PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#discussion_r2317650826
##########
src/backend/utils/sort/tuplesort.c:
##########
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
!alltuples)
return;
+ /*
+ * do nothing if we are told to finish execution.
+ */
+ if (QueryFinishPending)
Review Comment:
> it means enter dumptuples twice ?
Yes, dumptuples may be called multi times.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#discussion_r2317636491
##########
src/backend/utils/sort/tuplesort.c:
##########
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
!alltuples)
return;
+ /*
+ * do nothing if we are told to finish execution.
+ */
+ if (QueryFinishPending)
Review Comment:
it means enter dumptuples twice ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "my-ship-it (via GitHub)" <gi...@apache.org>.
my-ship-it merged PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "HuSen8891 (via GitHub)" <gi...@apache.org>.
HuSen8891 commented on PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#issuecomment-3243929342
> any stack to help to review ?
#0 0x00007f225274335b in raise () from /lib64/libpthread.so.0
#1 0x00007f225329108a in StandardHandlerForSigillSigsegvSigbus_OnMainThread (processName=<optimized out>, postgres_signal_arg=11) at elog.c:5377
#2 <signal handler called>
#3 pg_detoast_datum_packed (datum=0x13618050) at fmgr.c:1765
#4 0x00007f2253245ec1 in varlenafastcmp_locale (x=325156800, y=325156944, ssup=0x1597390) at varlena.c:2267
#5 0x00007f22532e3d66 in ApplySortComparator (isNull1=false, isNull2=false, ssup=0x1597390, datum2=<optimized out>, datum1=<optimized out>)
at ../../../../src/include/utils/sortsupport.h:224
#6 ApplySortComparator (ssup=0x1597390, isNull2=<optimized out>, datum2=<optimized out>, isNull1=<optimized out>, datum1=<optimized out>)
at ../../../../src/include/utils/sortsupport.h:200
#7 comparetup_heap (a=0x7f22032251e8, b=0x7f2203225200, state=0x1596f80) at tuplesort.c:3861
#8 0x00007f22532dfba2 in qsort_tuple (data=<optimized out>, n=2054917, compare=0x7f22532e3d00 <comparetup_heap>, arg=arg@entry=0x1596f80)
at ../../../../src/include/lib/sort_template.h:313
#9 0x00007f22532e32bc in tuplesort_sort_memtuples (state=0x1596f80) at tuplesort.c:3656
#10 dumptuples (state=0x1596f80, alltuples=<optimized out>) at tuplesort.c:3281
#11 0x00007f22532e6e9e in tuplesort_performsort (state=state@entry=0x1596f80) at tuplesort.c:2121
#12 0x00007f2252f5f727 in ExecSort (pstate=0x1547db8) at nodeSort.c:151
#13 0x00007f2252f2ceba in ExecProcNodeGPDB (node=0x1547db8) at execProcnode.c:631
#14 ExecProcNodeFirst (node=0x1547db8) at execProcnode.c:592
#15 0x00007f2252f64a09 in ExecProcNode (node=0x1547db8) at ../../../src/include/executor/executor.h:281
#16 begin_partition (winstate=winstate@entry=0x1547888) at nodeWindowAgg.c:1369
#17 0x00007f2252f68c68 in ExecWindowAgg (pstate=0x1547888) at nodeWindowAgg.c:2427
#18 0x00007f2252f2ceba in ExecProcNodeGPDB (node=0x1547888) at execProcnode.c:631
#19 ExecProcNodeFirst (node=0x1547888) at execProcnode.c:592
#20 0x00007f2252f5d355 in ExecProcNode (node=0x1547888) at ../../../src/include/executor/executor.h:281
#21 ExecResult (pstate=0x15476e8) at nodeResult.c:124
#22 0x00007f2252f2ceba in ExecProcNodeGPDB (node=0x15476e8) at execProcnode.c:631
#23 ExecProcNodeFirst (node=0x15476e8) at execProcnode.c:592
#24 0x00007f2252f714ea in ExecProcNode (node=0x15476e8) at ../../../src/include/executor/executor.h:281
#25 execMotionSender (node=0x15473f8) at nodeMotion.c:231
#26 ExecMotion (pstate=0x15473f8) at nodeMotion.c:194
#27 0x00007f2252f2ceba in ExecProcNodeGPDB (node=0x15473f8) at execProcnode.c:631
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "HuSen8891 (via GitHub)" <gi...@apache.org>.
HuSen8891 commented on code in PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#discussion_r2317585413
##########
src/backend/utils/sort/tuplesort.c:
##########
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
!alltuples)
return;
+ /*
+ * do nothing if we are told to finish execution.
+ */
+ if (QueryFinishPending)
Review Comment:
tuplecontext is reset in above case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "HuSen8891 (via GitHub)" <gi...@apache.org>.
HuSen8891 commented on code in PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#discussion_r2317613636
##########
src/backend/utils/sort/tuplesort.c:
##########
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
!alltuples)
return;
+ /*
+ * do nothing if we are told to finish execution.
+ */
+ if (QueryFinishPending)
Review Comment:
> which caller reset tuplecontext ?
In dumptuples, the tuplecontext is reset when all memtuples are consumed or QueryFinishPending is set to true.
##########
src/backend/utils/sort/tuplesort.c:
##########
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
!alltuples)
return;
+ /*
+ * do nothing if we are told to finish execution.
+ */
+ if (QueryFinishPending)
Review Comment:
In dumptuples, the tuplecontext is reset when all memtuples are consumed or QueryFinishPending is set to true.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [PR] Fix: quick exit in dumptuples if query execution is finished [cloudberry]
Posted by "HuSen8891 (via GitHub)" <gi...@apache.org>.
HuSen8891 commented on code in PR #1338:
URL: https://github.com/apache/cloudberry/pull/1338#discussion_r2317650826
##########
src/backend/utils/sort/tuplesort.c:
##########
@@ -3232,6 +3232,14 @@ dumptuples(Tuplesortstate *state, bool alltuples)
!alltuples)
return;
+ /*
+ * do nothing if we are told to finish execution.
+ */
+ if (QueryFinishPending)
Review Comment:
Yes, dumptuples may be called multi times.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org