mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
Add some recursion and looping defenses in prepjointree.c.
Andrey Lepikhov demonstrated a case where we spend an unreasonable amount of time in pull_up_subqueries(). Not only is that recursing with no explicit check for stack overrun, but the code seems not interruptable by control-C. Let's stick a CHECK_FOR_INTERRUPTS there, along with sprinkling some stack depth checks. An actual fix for the excessive time consumption seems a bit risky to back-patch; but this isn't, so let's do so. Discussion: https://postgr.es/m/703c09a2-08f3-d2ec-b33d-dbecd62428b8@postgrespro.ru
This commit is contained in:
parent
73bb72f0ca
commit
5beb7881fb
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
#include "funcapi.h"
|
#include "funcapi.h"
|
||||||
|
#include "miscadmin.h"
|
||||||
#include "nodes/makefuncs.h"
|
#include "nodes/makefuncs.h"
|
||||||
#include "nodes/multibitmapset.h"
|
#include "nodes/multibitmapset.h"
|
||||||
#include "nodes/nodeFuncs.h"
|
#include "nodes/nodeFuncs.h"
|
||||||
@ -308,6 +309,9 @@ static Node *
|
|||||||
pull_up_sublinks_jointree_recurse(PlannerInfo *root, Node *jtnode,
|
pull_up_sublinks_jointree_recurse(PlannerInfo *root, Node *jtnode,
|
||||||
Relids *relids)
|
Relids *relids)
|
||||||
{
|
{
|
||||||
|
/* Since this function recurses, it could be driven to stack overflow. */
|
||||||
|
check_stack_depth();
|
||||||
|
|
||||||
if (jtnode == NULL)
|
if (jtnode == NULL)
|
||||||
{
|
{
|
||||||
*relids = NULL;
|
*relids = NULL;
|
||||||
@ -805,6 +809,11 @@ pull_up_subqueries_recurse(PlannerInfo *root, Node *jtnode,
|
|||||||
JoinExpr *lowest_nulling_outer_join,
|
JoinExpr *lowest_nulling_outer_join,
|
||||||
AppendRelInfo *containing_appendrel)
|
AppendRelInfo *containing_appendrel)
|
||||||
{
|
{
|
||||||
|
/* Since this function recurses, it could be driven to stack overflow. */
|
||||||
|
check_stack_depth();
|
||||||
|
/* Also, since it's a bit expensive, let's check for query cancel. */
|
||||||
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
Assert(jtnode != NULL);
|
Assert(jtnode != NULL);
|
||||||
if (IsA(jtnode, RangeTblRef))
|
if (IsA(jtnode, RangeTblRef))
|
||||||
{
|
{
|
||||||
@ -1937,6 +1946,9 @@ is_simple_union_all(Query *subquery)
|
|||||||
static bool
|
static bool
|
||||||
is_simple_union_all_recurse(Node *setOp, Query *setOpQuery, List *colTypes)
|
is_simple_union_all_recurse(Node *setOp, Query *setOpQuery, List *colTypes)
|
||||||
{
|
{
|
||||||
|
/* Since this function recurses, it could be driven to stack overflow. */
|
||||||
|
check_stack_depth();
|
||||||
|
|
||||||
if (IsA(setOp, RangeTblRef))
|
if (IsA(setOp, RangeTblRef))
|
||||||
{
|
{
|
||||||
RangeTblRef *rtr = (RangeTblRef *) setOp;
|
RangeTblRef *rtr = (RangeTblRef *) setOp;
|
||||||
|
Loading…
Reference in New Issue
Block a user