MXS-1248: Further modifications for CTE

- Fields in CTEs are marked as being used in subselects.
- In qc_mysqlembedded all selects must be walked if CTE is present.
- In qc_sqlite unions need special handling.
This commit is contained in:
Johan Wikman
2017-06-30 12:47:46 +02:00
parent b5d54292a4
commit d060320b36
2 changed files with 33 additions and 16 deletions

View File

@ -2872,6 +2872,9 @@ int32_t qc_mysql_get_field_info(GWBUF* buf, const QC_FIELD_INFO** infos, uint32_
#ifdef CTE_SUPPORTED #ifdef CTE_SUPPORTED
if (lex->with_clauses_list) if (lex->with_clauses_list)
{ {
usage &= ~QC_USED_IN_SELECT;
usage |= QC_USED_IN_SUBSELECT;
With_clause* with_clause = lex->with_clauses_list; With_clause* with_clause = lex->with_clauses_list;
while (with_clause) while (with_clause)
@ -2923,6 +2926,13 @@ int32_t qc_mysql_get_field_info(GWBUF* buf, const QC_FIELD_INFO** infos, uint32_
} }
} }
#ifdef CTE_SUPPORTED
if ((lex->sql_command == SQLCOM_SET_OPTION) ||
(lex->with_clauses_list))
#else
if (lex->sql_command == SQLCOM_SET_OPTION)
#endif
{
if (lex->sql_command == SQLCOM_SET_OPTION) if (lex->sql_command == SQLCOM_SET_OPTION)
{ {
#if defined(WAY_TO_DOWNCAST_SET_VAR_BASE_EXISTS) #if defined(WAY_TO_DOWNCAST_SET_VAR_BASE_EXISTS)
@ -2939,7 +2949,9 @@ int32_t qc_mysql_get_field_info(GWBUF* buf, const QC_FIELD_INFO** infos, uint32_
} }
#endif #endif
// ...so, we will simply assume that any nested selects are // ...so, we will simply assume that any nested selects are
// from statements like "set @a:=(SELECT a from t1)". // from statements like "set @a:=(SELECT a from t1)". The
// code after the closing }.
}
usage &= ~QC_USED_IN_SELECT; usage &= ~QC_USED_IN_SELECT;
usage |= QC_USED_IN_SUBSELECT; usage |= QC_USED_IN_SUBSELECT;

View File

@ -1081,7 +1081,7 @@ static void update_field_infos_from_with(QC_SQLITE_INFO* info,
if (pCte->pSelect) if (pCte->pSelect)
{ {
update_field_infos_from_select(info, pCte->pSelect, QC_USED_IN_SELECT, NULL); update_field_infos_from_select(info, pCte->pSelect, QC_USED_IN_SUBSELECT, NULL);
} }
} }
} }
@ -1487,6 +1487,11 @@ static void update_field_infos_from_select(QC_SQLITE_INFO* info,
{ {
update_field_infos_from_with(info, pSelect->pWith); update_field_infos_from_with(info, pSelect->pWith);
} }
if ((pSelect->op == TK_UNION) && pSelect->pPrior)
{
update_field_infos_from_select(info, pSelect->pPrior, usage, pExclude);
}
} }
static void update_database_names(QC_SQLITE_INFO* info, const char* zDatabase) static void update_database_names(QC_SQLITE_INFO* info, const char* zDatabase)