Commit 57ce0bab authored by Alexander Barkov's avatar Alexander Barkov

A cleanup for MDEV-19908 Add class Type_collection

Moving geometry types aggregation inside Type_collection_geometry

This change introduces a static method Type_aggregator::find_handler_in_array(),
which will later be reused by other data type plugins.
parent c2d8db66
......@@ -7001,6 +7001,7 @@ extern MYSQL_PLUGIN_IMPORT Type_handler_interval_DDhhmmssff
class Type_aggregator
{
bool m_is_commutative;
public:
class Pair
{
public:
......@@ -7018,6 +7019,23 @@ class Type_aggregator
return m_handler1 == handler1 && m_handler2 == handler2;
}
};
static const Type_handler *
find_handler_in_array(const Type_aggregator::Pair *pairs,
const Type_handler *h1,
const Type_handler *h2,
bool commutative)
{
for (const Type_aggregator::Pair *p= pairs; p->m_result; p++)
{
if (p->eq(h1, h2))
return p->m_result;
if (commutative && p->eq(h2, h1))
return p->m_result;
}
return NULL;
}
private:
Dynamic_array<Pair> m_array;
const Pair* find_pair(const Type_handler *handler1,
const Type_handler *handler2) const;
......
......@@ -147,23 +147,84 @@ Type_handler_geometry::type_handler_frm_unpack(const uchar *buffer) const
}
const Type_handler *
Type_collection_geometry::aggregate_for_comparison(const Type_handler *a,
const Type_handler *b)
const
{
const Type_handler *h;
if ((h= aggregate_common(a, b)) ||
(h= aggregate_if_null(a, b)) ||
(h= aggregate_if_long_blob(a, b)))
return h;
return NULL;
}
const Type_handler *
Type_collection_geometry::aggregate_for_result(const Type_handler *a,
const Type_handler *b)
const
{
const Type_handler *h;
if ((h= aggregate_common(a, b)) ||
(h= aggregate_if_null(a, b)) ||
(h= aggregate_if_long_blob(a, b)) ||
(h= aggregate_if_string(a, b)))
return h;
return NULL;
}
const Type_handler *
Type_collection_geometry::aggregate_for_min_max(const Type_handler *a,
const Type_handler *b)
const
{
const Type_handler *h;
if ((h= aggregate_common(a, b)) ||
(h= aggregate_if_null(a, b)) ||
(h= aggregate_if_long_blob(a, b)) ||
(h= aggregate_if_string(a, b)))
return h;
return NULL;
}
const Type_handler *
Type_collection_geometry::aggregate_if_string(const Type_handler *a,
const Type_handler *b) const
{
if (a->type_collection() == this)
{
DBUG_ASSERT(b->type_collection() != this);
swap_variables(const Type_handler *, a, b);
}
if (a == &type_handler_hex_hybrid ||
a == &type_handler_tiny_blob ||
a == &type_handler_blob ||
a == &type_handler_medium_blob ||
a == &type_handler_varchar ||
a == &type_handler_string)
return &type_handler_long_blob;
return NULL;
}
#ifndef DBUG_OFF
bool Type_collection_geometry::init_aggregators(Type_handler_data *data,
const Type_handler *geom) const
{
Type_aggregator *r= &data->m_type_aggregator_for_result;
Type_aggregator *c= &data->m_type_aggregator_for_comparison;
return
r->add(geom, &type_handler_null, geom) ||
r->add(geom, &type_handler_hex_hybrid, &type_handler_long_blob) ||
r->add(geom, &type_handler_tiny_blob, &type_handler_long_blob) ||
r->add(geom, &type_handler_blob, &type_handler_long_blob) ||
r->add(geom, &type_handler_medium_blob, &type_handler_long_blob) ||
r->add(geom, &type_handler_long_blob, &type_handler_long_blob) ||
r->add(geom, &type_handler_varchar, &type_handler_long_blob) ||
r->add(geom, &type_handler_string, &type_handler_long_blob) ||
c->add(geom, &type_handler_null, geom) ||
c->add(geom, &type_handler_long_blob, &type_handler_long_blob);
r->add(geom, &type_handler_string, &type_handler_long_blob);
}
#endif
bool Type_collection_geometry::init(Type_handler_data *data)
......@@ -173,8 +234,7 @@ bool Type_collection_geometry::init(Type_handler_data *data)
if (nct->add(&type_handler_point,
&type_handler_varchar,
&type_handler_long_blob))
return true;
#endif // DBUG_OFF
return true;
return
init_aggregators(data, &type_handler_geometry) ||
init_aggregators(data, &type_handler_geometrycollection) ||
......@@ -184,6 +244,8 @@ bool Type_collection_geometry::init(Type_handler_data *data)
init_aggregators(data, &type_handler_multipoint) ||
init_aggregators(data, &type_handler_multilinestring) ||
init_aggregators(data, &type_handler_multipolygon);
#endif // DBUG_OFF
return false;
}
......
......@@ -280,28 +280,37 @@ class Type_collection_geometry: public Type_collection
return &type_handler_geometry;
return NULL;
}
const Type_handler *aggregate_if_null(const Type_handler *a,
const Type_handler *b) const
{
return a == &type_handler_null ? b :
b == &type_handler_null ? a :
NULL;
}
const Type_handler *aggregate_if_long_blob(const Type_handler *a,
const Type_handler *b) const
{
return a == &type_handler_long_blob ? &type_handler_long_blob :
b == &type_handler_long_blob ? &type_handler_long_blob :
NULL;
}
const Type_handler *aggregate_if_string(const Type_handler *a,
const Type_handler *b) const;
#ifndef DBUG_OFF
bool init_aggregators(Type_handler_data *data, const Type_handler *geom) const;
#endif
public:
bool init(Type_handler_data *data) override;
const Type_handler *handler_by_name(const LEX_CSTRING &name) const override;
const Type_handler *aggregate_for_result(const Type_handler *a,
const Type_handler *b)
const override
{
return aggregate_common(a, b);
}
const override;
const Type_handler *aggregate_for_comparison(const Type_handler *a,
const Type_handler *b)
const override
{
return aggregate_common(a, b);
}
const override;
const Type_handler *aggregate_for_min_max(const Type_handler *a,
const Type_handler *b)
const override
{
return aggregate_common(a, b);
}
const override;
const Type_handler *aggregate_for_num_op(const Type_handler *a,
const Type_handler *b)
const override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment