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
Crash if more than one INITPLAN function is used in query #9953
Comments
Huh? This feature went into master but I'm a bit surprised we are seeing this bug on 6X_STABLE... |
I bumped into this while refactoring ShareInputScans. This function INITPLAN sharing mechanism is quite similar to the way ShareInputScans work. One important difference is that the tuplestore created for INITPLAN function is carried oer from the gang that exeucutes the init plan, to the gang that executes the main plan. A similar scenario would actually be possible with ShareInputScans too, if you have a query with a CTE that's used both in an InitPlan, and the main plan. To avoid that situation, the CTE planning code prevents CTE sharing from happening across subplans. I think there's an opportunity here to handle both cases: INITPLAN functions, and CTE sharing from InitPlans, with the same code. This INITPLAN handling in FunctionScans is a pretty big hack, but perhaps we could use the ShareInputScan infrastructure we have? So instead of having special code in FunctionScan, the planner would generate a ShareInputScan on top of the FunctionScan. So the plan would look like this:
Now, as I mentioned earlier, ShareInputScans don't actually support that at the moment. Even though the InitPlan would be executed and the tuplestore generated, it would get destroyed after the InitPlan was executed. But maybe we could find a way to fix that. It would be pretty straightforward to just not destroy the tuplestore at the end of the InitPlan execution. But then it will get leaked on abort. And actually, the FunctionScan hack has that exact same problem; if the FunctionScan doesn't get executed in the main plan slice, the temporary file is leaked. For example:
|
I admit I didn't test it on 6X_STABLE, but the feature was backpatched so I assumed it's similarly buggy on 6X_STABLE. I was very surprised to see that it was backpatched to 6X_STABLE, though. |
Thanks @hlinnaka ! I fixed the multiple INITPLAN function by introducing the initplan_id for each tuplestore file. So different INITPLAN fucntions could use different tuplestore files. Details in #10156 I haven't tried your Share Input Scan + Function scan solution(possible in my first glance), I opened a new issue #10157 to track this idea. |
@zhangh43, why closed? |
Ah, this was fixed in #10156. Gotcha |
Greenplum version or build
master, 6X_STABLE
Step to reproduce the behavior
The INITPLAN mechanism isn't prepared to deal two INITPLAN functions being used in the same query, and it mixes up the tuplestores of the two. In this case, it leads to a crash, when an integer is interpreted as a text pointer. With different datatypes, you would get incorrect query results or other errors instead.
The text was updated successfully, but these errors were encountered: