Bail out earlier when walking parse tree
No point walking the parse tree, if no information will be collected.
This commit is contained in:
@ -484,19 +484,27 @@ public:
|
||||
// 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.
|
||||
* @param zTable The table or NULL.
|
||||
* @param zColumn The column.
|
||||
* Only if we are in Oracle mode or parsing as 10.3 we need to check.
|
||||
*
|
||||
* @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,
|
||||
const char* zTable,
|
||||
const char* zColumn) const
|
||||
bool must_check_sequence_related_functions() 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
const char** pzDatabase,
|
||||
const char** pzTable)
|
||||
@ -614,13 +638,14 @@ public:
|
||||
|
||||
// NOTE: This must be first, so that the type mask is properly updated
|
||||
// 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;
|
||||
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
|
||||
// has already been collected, we just return.
|
||||
@ -669,6 +694,8 @@ public:
|
||||
bool should_collect_database = zDatabase &&
|
||||
(should_collect_alias || should_collect(QC_COLLECT_DATABASES));
|
||||
|
||||
if (should_collect_table || should_collect_database)
|
||||
{
|
||||
const char* zCollected_database = NULL;
|
||||
const char* zCollected_table = NULL;
|
||||
|
||||
@ -707,6 +734,7 @@ public:
|
||||
pAliases->insert(QcAliases::value_type(zAlias, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t type_check_dynamic_string(const Expr* pExpr)
|
||||
{
|
||||
@ -1145,11 +1173,14 @@ public:
|
||||
const char* zTable;
|
||||
const char* zColumn;
|
||||
|
||||
if (must_check_sequence_related_functions() || must_collect_fields())
|
||||
{
|
||||
if (get_field_name(pExpr, &zDatabase, &zTable, &zColumn))
|
||||
{
|
||||
update_field_info(pAliases, zDatabase, zTable, zColumn, pExclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_field_infos_from_exprlist(QcAliases* pAliases,
|
||||
const ExprList* pEList,
|
||||
@ -1166,6 +1197,8 @@ public:
|
||||
void update_field_infos_from_idlist(QcAliases* pAliases,
|
||||
const IdList* pIds,
|
||||
const ExprList* pExclude)
|
||||
{
|
||||
if (must_check_sequence_related_functions() || must_collect_fields())
|
||||
{
|
||||
for (int i = 0; i < pIds->nId; ++i)
|
||||
{
|
||||
@ -1174,6 +1207,7 @@ public:
|
||||
update_field_info(pAliases, NULL, NULL, pItem->zName, pExclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum compound_approach_t
|
||||
{
|
||||
|
Reference in New Issue
Block a user