From fa83259c62df3a15703139684346ac8cfc00505c Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 2 Jun 2021 13:50:41 +0300 Subject: [PATCH] MXS-3585 Fix problem --- query_classifier/qc_sqlite/qc_sqlite.cc | 30 ++++++++++++++----- .../qc_sqlite/sqlite-src-3110100/src/parse.y | 6 ++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/query_classifier/qc_sqlite/qc_sqlite.cc b/query_classifier/qc_sqlite/qc_sqlite.cc index fdc094a85..34d9835a2 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.cc +++ b/query_classifier/qc_sqlite/qc_sqlite.cc @@ -712,8 +712,6 @@ public: void update_names(const char* zDatabase, const char* zTable, const char* zAlias, QcAliases* pAliases) { - mxb_assert(zTable); - bool should_collect_alias = pAliases && zAlias && should_collect(QC_COLLECT_FIELDS); bool should_collect_table = should_collect_alias || should_collect(QC_COLLECT_TABLES); bool should_collect_database = zDatabase @@ -736,7 +734,7 @@ public: exposed_sqlite3Dequote(database); } - if (should_collect_table) + if (should_collect_table && zTable) { if (strcasecmp(zTable, "DUAL") != 0) { @@ -1437,9 +1435,14 @@ public: update_names(pSrc->a[i].zDatabase, pSrc->a[i].zName, pSrc->a[i].zAlias, pAliases); } - if (pSrc->a[i].pSelect && pSrc->a[i].pSelect->pSrc) + if (pSrc->a[i].pSelect) { - update_names_from_srclist(pAliases, pSrc->a[i].pSelect->pSrc); + maxscaleCollectInfoFromSelect(nullptr, pSrc->a[i].pSelect, 1); // 1 denotes subselect. + + if (pSrc->a[i].pSelect->pSrc) // The FROM clause + { + update_names_from_srclist(pAliases, pSrc->a[i].pSelect->pSrc); + } } if (pSrc->a[i].pOn) @@ -1818,6 +1821,11 @@ public: { const SrcList::SrcList_item* pItem = &pUsing->a[i]; + if (pItem->pSelect) + { + maxscaleCollectInfoFromSelect(nullptr, pItem->pSelect, 1); // 1 denotes subselect. + } + update_names(pItem->zDatabase, pItem->zName, pItem->zAlias, &aliases); } @@ -1834,7 +1842,7 @@ public: { SrcList::SrcList_item* pItem = &pUsing->a[j++]; - if (strcasecmp(pTable->zName, pItem->zName) == 0) + if (pItem->zName && (strcasecmp(pTable->zName, pItem->zName) == 0)) { isSame = true; } @@ -2082,7 +2090,15 @@ public: m_type_mask = QUERY_TYPE_WRITE; m_operation = QUERY_OP_UPDATE; update_names_from_srclist(&aliases, pTabList); - m_has_clause = ((pWhere && pWhere->op != TK_IN) ? true : false); + // If this is an UPDATE ... SELECT ... and the select has a where clause + // or a limit, then m_has_clause has been set already. + if (!m_has_clause) + { + if (pWhere && pWhere->op != TK_IN) + { + m_has_clause = true; + } + } if (pChanges) { diff --git a/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y b/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y index a2b16eac4..b2be0148f 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y @@ -1592,10 +1592,8 @@ table_factor(A) ::= nm(X) DOT nm(Y) as_opt id(Z). { A = sqlite3SrcListAppendFromTerm(pParse, 0, &X, &Y, &Z, 0, 0, 0); } -table_factor(A) ::= LP oneselect(S) RP as_opt id. { - maxscaleCollectInfoFromSelect(pParse, S, 1); - sqlite3SelectDelete(pParse->db, S); - A = 0; +table_factor(A) ::= LP oneselect(S) RP as_opt id(Z). { + A = sqlite3SrcListAppendFromTerm(pParse, 0, 0, 0, &Z, S, 0, 0); } %type table_reference {SrcList*}