Bail out earlier when walking parse tree

No point walking the parse tree, if no information will be
collected.
This commit is contained in:
Johan Wikman
2017-10-06 12:59:31 +03:00
parent ecb56ef540
commit a51d23ded0

View File

@ -484,19 +484,27 @@ public:
// PUBLIC for now at least. // PUBLIC for now at least.
/** /**
* Returns whether a field is sequence related. * Returns whether sequence related functions should be checked for.
* *
* @param zDatabase The database/schema or NULL. * Only if we are in Oracle mode or parsing as 10.3 we need to check.
* @param zTable The table or NULL.
* @param zColumn The column.
* *
* @return True, if the field is sequence related, false otherwise. * @return True, if they need to be checked for, false otherwise.
*/ */
bool is_sequence_related_field(const char* zDatabase, bool must_check_sequence_related_functions() const
const char* zTable,
const char* zColumn) const
{ {
return is_sequence_related_function(zColumn); return (m_sql_mode == QC_SQL_MODE_ORACLE) || (this_unit.parse_as == QC_PARSE_AS_103);
}
/**
* Returns whether fields should be collected.
*
* @return True, if should be, false otherwise.
*/
bool must_collect_fields() const
{
// We must collect if fields should be collected and they have not
// been collected yet.
return (m_collect & QC_COLLECT_FIELDS) && !(m_collected & QC_COLLECT_FIELDS);
} }
/** /**
@ -534,6 +542,22 @@ public:
return rv; return rv;
} }
/**
* Returns whether a field is sequence related.
*
* @param zDatabase The database/schema or NULL.
* @param zTable The table or NULL.
* @param zColumn The column.
*
* @return True, if the field is sequence related, false otherwise.
*/
bool is_sequence_related_field(const char* zDatabase,
const char* zTable,
const char* zColumn) const
{
return is_sequence_related_function(zColumn);
}
static void honour_aliases(const QcAliases* pAliases, static void honour_aliases(const QcAliases* pAliases,
const char** pzDatabase, const char** pzDatabase,
const char** pzTable) const char** pzTable)
@ -614,13 +638,14 @@ public:
// NOTE: This must be first, so that the type mask is properly updated // NOTE: This must be first, so that the type mask is properly updated
// NOTE: in case zColumn is "currval" etc. // NOTE: in case zColumn is "currval" etc.
if (is_sequence_related_field(zDatabase, zTable, zColumn)) if (must_check_sequence_related_functions() &&
is_sequence_related_field(zDatabase, zTable, zColumn))
{ {
m_type_mask |= QUERY_TYPE_WRITE; m_type_mask |= QUERY_TYPE_WRITE;
return; return;
} }
if (!(m_collect & QC_COLLECT_FIELDS) || (m_collected & QC_COLLECT_FIELDS)) if (!must_collect_fields())
{ {
// If field information should not be collected, or if field information // If field information should not be collected, or if field information
// has already been collected, we just return. // has already been collected, we just return.
@ -669,6 +694,8 @@ public:
bool should_collect_database = zDatabase && bool should_collect_database = zDatabase &&
(should_collect_alias || should_collect(QC_COLLECT_DATABASES)); (should_collect_alias || should_collect(QC_COLLECT_DATABASES));
if (should_collect_table || should_collect_database)
{
const char* zCollected_database = NULL; const char* zCollected_database = NULL;
const char* zCollected_table = NULL; const char* zCollected_table = NULL;
@ -707,6 +734,7 @@ public:
pAliases->insert(QcAliases::value_type(zAlias, value)); pAliases->insert(QcAliases::value_type(zAlias, value));
} }
} }
}
static int32_t type_check_dynamic_string(const Expr* pExpr) static int32_t type_check_dynamic_string(const Expr* pExpr)
{ {
@ -1145,11 +1173,14 @@ public:
const char* zTable; const char* zTable;
const char* zColumn; const char* zColumn;
if (must_check_sequence_related_functions() || must_collect_fields())
{
if (get_field_name(pExpr, &zDatabase, &zTable, &zColumn)) if (get_field_name(pExpr, &zDatabase, &zTable, &zColumn))
{ {
update_field_info(pAliases, zDatabase, zTable, zColumn, pExclude); update_field_info(pAliases, zDatabase, zTable, zColumn, pExclude);
} }
} }
}
void update_field_infos_from_exprlist(QcAliases* pAliases, void update_field_infos_from_exprlist(QcAliases* pAliases,
const ExprList* pEList, const ExprList* pEList,
@ -1166,6 +1197,8 @@ public:
void update_field_infos_from_idlist(QcAliases* pAliases, void update_field_infos_from_idlist(QcAliases* pAliases,
const IdList* pIds, const IdList* pIds,
const ExprList* pExclude) const ExprList* pExclude)
{
if (must_check_sequence_related_functions() || must_collect_fields())
{ {
for (int i = 0; i < pIds->nId; ++i) for (int i = 0; i < pIds->nId; ++i)
{ {
@ -1174,6 +1207,7 @@ public:
update_field_info(pAliases, NULL, NULL, pItem->zName, pExclude); update_field_info(pAliases, NULL, NULL, pItem->zName, pExclude);
} }
} }
}
enum compound_approach_t enum compound_approach_t
{ {