From 75509a67d41c0765a651f921dede3c5ff18ef222 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Sat, 5 Nov 2016 10:09:03 +0200 Subject: [PATCH] qc: Do not collect HAVING names A HAVING clause can only refer to names that already have been mentioned or if "SELECT *" is used. Either way, the HAVING names need not be separately collected. --- .../qc_mysqlembedded/qc_mysqlembedded.cc | 12 ++++++++---- query_classifier/qc_sqlite/qc_sqlite.c | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index 33df9ef25..eb992d770 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -2173,16 +2173,20 @@ void qc_get_field_info(GWBUF* buf, const QC_FIELD_INFO** infos, size_t* n_infos) if (lex->current_select->where) { update_field_infos(pi, COLLECT_WHERE, - lex->current_select->where, - &lex->current_select->item_list); + lex->current_select->where, + &lex->current_select->item_list); } +#if defined(COLLECT_HAVING_AS_WELL) + // A HAVING clause can only refer to fields that already have been + // mentioned. Consequently, they need not be collected. if (lex->current_select->having) { update_field_infos(pi, COLLECT_HAVING, - lex->current_select->having, - &lex->current_select->item_list); + lex->current_select->having, + &lex->current_select->item_list); } +#endif lex->current_select = lex->current_select->next_select_in_list(); } diff --git a/query_classifier/qc_sqlite/qc_sqlite.c b/query_classifier/qc_sqlite/qc_sqlite.c index e7d50bab1..fc6767dc6 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.c +++ b/query_classifier/qc_sqlite/qc_sqlite.c @@ -1029,7 +1029,11 @@ static void update_fields_infos_from_select(QC_SQLITE_INFO* info, if (pSelect->pHaving) { info->has_clause = true; +#if defined(COLLECT_HAVING_AS_WELL) + // A HAVING clause can only refer to fields that already have been + // mentioned. Consequently, they need not be collected. update_fields_infos(info, 0, pSelect->pHaving, QC_TOKEN_MIDDLE, pSelect->pEList); +#endif } }