From c662bea983ed9552ac4772e7d370551738290f96 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 14 Aug 2017 13:29:19 +0300 Subject: [PATCH] MXS-1359 Turn recursion into iteration In case of very large compound selects or an INSERT with many values, qc_sqlite could run out of stack space. To deal with that, the critical recursion is turned into an iteration. --- query_classifier/qc_sqlite/qc_sqlite.cc | 28 ++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/query_classifier/qc_sqlite/qc_sqlite.cc b/query_classifier/qc_sqlite/qc_sqlite.cc index 5684e0d51..4cfae297b 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.cc +++ b/query_classifier/qc_sqlite/qc_sqlite.cc @@ -1084,10 +1084,17 @@ public: } } + enum compound_approach_t + { + ANALYZE_COMPOUND_SELECTS, + IGNORE_COMPOUND_SELECTS + }; + void update_field_infos_from_select(QcAliases& aliases, const Select* pSelect, uint32_t usage, - const ExprList* pExclude) + const ExprList* pExclude, + compound_approach_t compound_approach = ANALYZE_COMPOUND_SELECTS) { if (pSelect->pSrc) { @@ -1156,20 +1163,31 @@ public: update_field_infos_from_with(&aliases, pSelect->pWith); } - if (((pSelect->op == TK_UNION) || (pSelect->op == TK_ALL)) && pSelect->pPrior) + if (compound_approach == ANALYZE_COMPOUND_SELECTS) { - update_field_infos_from_subselect(&aliases, pSelect->pPrior, usage, pExclude); + if (((pSelect->op == TK_UNION) || (pSelect->op == TK_ALL)) && pSelect->pPrior) + { + const Select* pPrior = pSelect->pPrior; + + while (pPrior) + { + update_field_infos_from_subselect(&aliases, pPrior, usage, pExclude, + IGNORE_COMPOUND_SELECTS); + pPrior = pPrior->pPrior; + } + } } } void update_field_infos_from_subselect(QcAliases* pAliases, const Select* pSelect, uint32_t usage, - const ExprList* pExclude) + const ExprList* pExclude, + compound_approach_t compound_approach = ANALYZE_COMPOUND_SELECTS) { QcAliases aliases(*pAliases); - update_field_infos_from_select(aliases, pSelect, usage, pExclude); + update_field_infos_from_select(aliases, pSelect, usage, pExclude, compound_approach); } void update_field_infos_from_with(QcAliases* pAliases, const With* pWith)