MXS-1364 Compare should report function column usage
This commit is contained in:
@ -962,11 +962,11 @@ public:
|
|||||||
|
|
||||||
out << m_column;
|
out << m_column;
|
||||||
|
|
||||||
out << "(";
|
out << "[";
|
||||||
char* s = qc_field_usage_mask_to_string(m_usage);
|
char* s = qc_field_usage_mask_to_string(m_usage);
|
||||||
out << s;
|
out << s;
|
||||||
free(s);
|
free(s);
|
||||||
out << ")";
|
out << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -1062,6 +1062,8 @@ public:
|
|||||||
QcFunctionInfo(const QC_FUNCTION_INFO& info)
|
QcFunctionInfo(const QC_FUNCTION_INFO& info)
|
||||||
: m_name(info.name)
|
: m_name(info.name)
|
||||||
, m_usage(info.usage)
|
, m_usage(info.usage)
|
||||||
|
, m_pFields(info.fields)
|
||||||
|
, m_nFields(info.n_fields)
|
||||||
{
|
{
|
||||||
// We want case-insensitive comparisons.
|
// We want case-insensitive comparisons.
|
||||||
std::transform(m_name.begin(), m_name.end(), m_name.begin(), tolower);
|
std::transform(m_name.begin(), m_name.end(), m_name.begin(), tolower);
|
||||||
@ -1071,7 +1073,8 @@ public:
|
|||||||
{
|
{
|
||||||
return
|
return
|
||||||
m_name == rhs.m_name &&
|
m_name == rhs.m_name &&
|
||||||
m_usage == rhs.m_usage;
|
m_usage == rhs.m_usage &&
|
||||||
|
have_same_fields(*this, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lt(const QcFunctionInfo& rhs) const
|
bool lt(const QcFunctionInfo& rhs) const
|
||||||
@ -1086,9 +1089,23 @@ public:
|
|||||||
{
|
{
|
||||||
rv = false;
|
rv = false;
|
||||||
}
|
}
|
||||||
|
else if (m_usage < rhs.m_usage)
|
||||||
|
{
|
||||||
|
rv = true;
|
||||||
|
}
|
||||||
|
else if (m_usage > rhs.m_usage)
|
||||||
|
{
|
||||||
|
rv = false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rv = (m_usage < rhs.m_usage);
|
std::set<string> lfs;
|
||||||
|
std::set<string> rfs;
|
||||||
|
|
||||||
|
get_fields(&lfs);
|
||||||
|
rhs.get_fields(&rfs);
|
||||||
|
|
||||||
|
rv = lfs < rfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
@ -1112,13 +1129,15 @@ public:
|
|||||||
{
|
{
|
||||||
rv = false;
|
rv = false;
|
||||||
}
|
}
|
||||||
else
|
else if (!have_same_fields(*i, *j))
|
||||||
{
|
{
|
||||||
|
rv = false;
|
||||||
|
}
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -1128,15 +1147,93 @@ public:
|
|||||||
out << m_name;
|
out << m_name;
|
||||||
|
|
||||||
out << "(";
|
out << "(";
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < m_nFields; ++i)
|
||||||
|
{
|
||||||
|
const QC_FIELD_NAME& name = m_pFields[i];
|
||||||
|
|
||||||
|
if (name.database)
|
||||||
|
{
|
||||||
|
out << name.database << ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.table)
|
||||||
|
{
|
||||||
|
out << name.table << ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
ss_dassert(name.column);
|
||||||
|
|
||||||
|
out << name.column;
|
||||||
|
|
||||||
|
if (i < m_nFields - 1)
|
||||||
|
{
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out << ")";
|
||||||
|
|
||||||
|
out << "[";
|
||||||
char* s = qc_field_usage_mask_to_string(m_usage);
|
char* s = qc_field_usage_mask_to_string(m_usage);
|
||||||
out << s;
|
out << s;
|
||||||
free(s);
|
free(s);
|
||||||
out << ")";
|
out << "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void get_fields(std::set<string>* pS) const
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_nFields; ++i)
|
||||||
|
{
|
||||||
|
pS->insert(get_field_name(m_pFields[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool have_same_fields(const QcFunctionInfo& lhs, const QcFunctionInfo& rhs)
|
||||||
|
{
|
||||||
|
bool rv = false;
|
||||||
|
|
||||||
|
if (lhs.m_nFields == rhs.m_nFields)
|
||||||
|
{
|
||||||
|
std::set<string> lfs;
|
||||||
|
lhs.get_fields(&lfs);
|
||||||
|
|
||||||
|
std::set<string> rfs;
|
||||||
|
rhs.get_fields(&rfs);
|
||||||
|
|
||||||
|
rv = (lfs == rfs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string get_field_name(const QC_FIELD_NAME& field)
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
|
||||||
|
if (field.database)
|
||||||
|
{
|
||||||
|
s += field.database;
|
||||||
|
s += ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field.table)
|
||||||
|
{
|
||||||
|
s += field.table;
|
||||||
|
s += ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
s += field.column;
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
uint32_t m_usage;
|
uint32_t m_usage;
|
||||||
|
const QC_FIELD_NAME* m_pFields;
|
||||||
|
uint32_t m_nFields;
|
||||||
};
|
};
|
||||||
|
|
||||||
ostream& operator << (ostream& out, const QcFunctionInfo& x)
|
ostream& operator << (ostream& out, const QcFunctionInfo& x)
|
||||||
|
Reference in New Issue
Block a user