MXS-1380 Parse UNIONs completely

Before this change, only db2.t2 was reported as table name for a
select like

    select * from db1.t1 union select * from db2.t2

With this change, db1.t1 and db2.t2 are reported.
This commit is contained in:
Johan Wikman
2017-08-31 13:23:47 +03:00
parent c5581faae7
commit 7cb3c68d1e
4 changed files with 43 additions and 13 deletions

View File

@ -167,10 +167,18 @@ static void update_field_infos_from_idlist(QC_SQLITE_INFO* info,
const IdList* pIds,
uint32_t usage,
const ExprList* pExclude);
static void update_field_infos_from_select(QC_SQLITE_INFO* info,
const Select* pSelect,
uint32_t usage,
const ExprList* pExclude);
typedef enum compound_approach
{
ANALYZE_COMPOUND_SELECTS,
IGNORE_COMPOUND_SELECTS
} compound_approach_t;
static void update_field_infos_from_select_compound(QC_SQLITE_INFO* info,
const Select* pSelect,
uint32_t usage,
const ExprList* pExclude,
compound_approach_t compound_approach);
#define update_field_infos_from_select(i, s, u, e)\
update_field_infos_from_select_compound(i, s, u, e, ANALYZE_COMPOUND_SELECTS)
static void update_function_info(QC_SQLITE_INFO* info,
const char* name,
uint32_t usage);
@ -1193,10 +1201,11 @@ static void update_field_infos_from_idlist(QC_SQLITE_INFO* info,
}
}
static void update_field_infos_from_select(QC_SQLITE_INFO* info,
const Select* pSelect,
uint32_t usage,
const ExprList* pExclude)
static void update_field_infos_from_select_compound(QC_SQLITE_INFO* info,
const Select* pSelect,
uint32_t usage,
const ExprList* pExclude,
compound_approach_t compound_approach)
{
if (pSelect->pSrc)
{
@ -1257,6 +1266,21 @@ static void update_field_infos_from_select(QC_SQLITE_INFO* info,
update_field_infos(info, 0, pSelect->pHaving, 0, QC_TOKEN_MIDDLE, pSelect->pEList);
#endif
}
if (compound_approach == ANALYZE_COMPOUND_SELECTS)
{
if (((pSelect->op == TK_UNION) || (pSelect->op == TK_ALL)) && pSelect->pPrior)
{
const Select* pPrior = pSelect->pPrior;
while (pPrior)
{
update_field_infos_from_select_compound(info, pPrior, usage, pExclude,
IGNORE_COMPOUND_SELECTS);
pPrior = pPrior->pPrior;
}
}
}
}
static void update_database_names(QC_SQLITE_INFO* info, const char* zDatabase)