-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Make viewquery a copy in rewriteTargetView()
Rather than expect the Query returned by get_view_query() to be read-only and then copy bits and pieces of it out, simply copy the entire structure when we get it. This addresses an issue where AcquireRewriteLocks, which is called by acquireLocksOnSubLinks(), scribbles on the parsetree passed in, which was actually an entry in relcache, leading to segfaults with certain view definitions. This also future-proofs us a bit for anyone adding more code to this path. The acquireLocksOnSubLinks() was added in commit c3e0ddd. Back-patch to 9.3 as that commit was.
- Loading branch information
commit f02137da88c49125a20d7c51ae9932e47eb61f93
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
<
9E12
/a>
|
@@ -1908,6 +1908,9 @@ fireRules(Query *parsetree, | |
| * | ||
| * Caller should have verified that the relation is a view, and therefore | ||
| * we should find an ON SELECT action. | ||
| * | ||
| * Note that the pointer returned is into the relcache and therefore must | ||
| * be treated as read-only to the caller and not modified or scribbled on. | ||
| */ | ||
| Query * | ||
| get_view_query(Relation view) | ||
|
|
@@ -2494,9 +2497,16 @@ rewriteTargetView(Query *parsetree, Relation view) | |
| List *view_targetlist; | ||
| ListCell *lc; | ||
|
|
||
| /* The view must be updatable, else fail */ | ||
| viewquery = get_view_query(view); | ||
| /* | ||
| * Get the Query from the view's ON SELECT rule. We're going to munge the | ||
| * Query to change the view's base relation into the target relation, | ||
| * along with various other changes along the way, so we need to make a | ||
| * copy of it (get_view_query() returns a pointer into the relcache, so we | ||
| * have to treat it as read-only). | ||
| */ | ||
| viewquery = copyObject(get_view_query(view)); | ||
|
|
||
| /* The view must be updatable, else fail */ | ||
| auto_update_detail = | ||
| view_query_is_auto_updatable(viewquery, | ||
| parsetree->commandType != CMD_DELETE); | ||
|
|
@@ -2648,7 +2658,7 @@ rewriteTargetView(Query *parsetree, Relation view) | |
| * outer query. Perhaps someday we should refactor things enough so that | ||
| * we can share code with the planner.) | ||
| */ | ||
| new_rte = (RangeTblEntry *) copyObject(base_rte); | ||
| new_rte = (RangeTblEntry *) base_rte; | ||
| parsetree->rtable = lappend(parsetree->rtable, new_rte); | ||
| new_rt_index = list_length(parsetree->rtable); | ||
|
|
||
|
|
@@ -2660,14 +2670,14 @@ rewriteTargetView(Query *parsetree, Relation view) | |
| new_rte->inh = false; | ||
|
|
||
| /* | ||
| * Make a copy of the view's targetlist, adjusting its Vars to reference | ||
| * the new target RTE, ie make their varnos be new_rt_index instead of | ||
| * base_rt_index. There can be no Vars for other rels in the tlist, so | ||
| * this is sufficient to pull up the tlist expressions for use in the | ||
| * outer query. The tlist will provide the replacement expressions used | ||
| * by ReplaceVarsFromTargetList below. | ||
| * Adjust the view's targetlist Vars to reference the new target RTE, ie | ||
| * make their varnos be new_rt_index instead of base_rt_index. There can | ||
| * be no Vars for other rels in the tlist, so this is sufficient to pull | ||
| * up the tlist expressions for use in the outer query. The tlist will | ||
| * provide the replacement expressions used by ReplaceVarsFromTargetList | ||
| * below. | ||
| */ | ||
| view_targetlist = copyObject(viewquery->targetList); | ||
| view_targetlist = viewquery->targetList; | ||
|
|
||
| ChangeVarNodes((Node *) view_targetlist, | ||
| base_rt_index, | ||
|
|
@@ -2813,7 +2823,7 @@ rewriteTargetView(Query *parsetree, Relation view) | |
| if (parsetree->commandType != CMD_INSERT && | ||
| viewquery->jointree->quals != NULL) | ||
| { | ||
| Node *viewqual = (Node *) copyObject(viewquery->jointree->quals); | ||
| Node *viewqual = (Node *) viewquery->jointree->quals; | ||
|
|
||
| ChangeVarNodes(viewqual, base_rt_index, new_rt_index, 0); | ||
|
|
||
|
|
@@ -2890,7 +2900,7 @@ rewriteTargetView(Query *parsetree, Relation view) | |
|
|
||
| if (viewquery->jointree->quals != NULL) | ||
| { | ||
| wco->qual = (Node *) copyObject(viewquery->jointree->quals); | ||
| wco->qual = (Node *) viewquery->jointree->quals; | ||
| ChangeVarNodes(wco->qual, base_rt_index, new_rt_index, 0); | ||
|
|
||
| /* | ||
|
|
||
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
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
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.
Rel9_4_stable_first #6
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
Uh oh!
There was an error while loading. Please reload this page.
Rel9_4_stable_first #6
Changes from 1 commit
ff2ee45d509560928d022f7ed46522b9ce7fe939d9fc3649fbef45843da9c06747ca6612da677ce6e50a7f7fd9b37d10c5296022974fc81eb17ce621e03094b6e36730198a8d8582cf1ac711ddb74af4083d0049ed476662244c0648c6a1a7786fe021a7c0759d310b907f3a97d0712835d2fc1541ec18e2e46a95ed2d2cf7d896af38070de32c5f17496abafa9fc3a32b68eda3e58e7d546ce74ff753c0da864c348dd2849917edc961f4067d0f7a8400829b62c87003f9b635091f391128b7735435af2171661109def0c0215b2c5e38b9bb1d9798e454979955798ff4cbc14075fc493840f9439b65e13ac4c04d9541916d58b5a0c02edbed3f6d2fc66bf1ecae3a5d250a8868b79affdf2a2e96b697d25c7d73d70127fe86f7f56f9d9115e9457e491f2bc9853e622c570557f54b506dd4b4bba442e44a6e24b6eb5fcbdde29e8cf4eed9774fda0ecf4a9f189747a850d7152f21c510000563f40b7fc71254f3357287abcb45eca6cffa17165589017e626f9be352e3cb5554b301d9561711e7f9d038aa89788e35af69c01f24379a486f358cff4adfd40879a987cdfebf1b8987d33ab56a6c4c078bc496ccc95595d5bb7c6b06a8e30fbf4409892cc247ea461b29a40f7acad95f91c4e33d357b4b7fc1dd346cc2fab14e0e85cb94f0cc6bad0901d6856a79a57145d35ee0df4dc6a67bb7ad6960423697e1f8757a09824cdd638aee6bdef1361c7bee38a4a42819aceaaffae5eb9a46f8e168dfeacb6c649f74926590d201f02137d2c8ae64d07afa4f56802a70ff7370a29cf6f98bc20aba82403b3e8fc12e116a76eccf0f9b3b3f146b4cd88ee2561cd3840aab4b73add6d828c558b2c7aca3d882c59233b0512aa06259831c22bacbdda478b7aaa22815757393208ab49f87fc5d5e98b3d5282b39831280d05c5849b6ee76281e95a2ccaaa223a0c33d1a8c27fda6411e2b01f3294c2099b9131b792fed6deeb282a62e73ed2a533b2642fdc31395e54757b101dcaa1efb7919e46944492ab5e3ad502ccbb01f2f66e2977c616ada5cf6af461fa7b754716bec4d0f6830cae5c4973178e3293f6a605780c925c9b69d5c0a20d078504ec90bd51de55965eb597e41ed750b20c7327568de488d2105091a9613ee465dd92a50f50a3b94b3a61920833fa4715fb3ea0489f8372e3e84fd2afe9546041d388457c696416b1d7e31314da9362043b491a4f37d098857488File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.