Commit 50bcda01 authored by Alexander Barkov's avatar Alexander Barkov Committed by Sergei Golubchik

Changing the FixedBinTypeBundle parameter to a "storage class" instead of sizes

- Adding a new template FixedBinTypeStorage.

- Restoring classes UUID and Inet6
  as primitive "storage classes" for their data types.
  They derive from FixedBinTypeStorage.
  These storage classes have very few server dependencies so they
  can later be easily reused in smart engines, e.g. ColumnStore.

- Changing the FixedBinTypeBundle parameter from
  <size_t NATIVE_LEN, size_t MAX_CHAR_LEN> to <class FbtImpl>
  and fixing UUID and INET6 bundles to get their storage
  classes as a parameter.
parent b1fab9bf
...@@ -168,8 +168,7 @@ bool Inet4::ascii_to_ipv4(const char *str, size_t str_length) ...@@ -168,8 +168,7 @@ bool Inet4::ascii_to_ipv4(const char *str, size_t str_length)
IPv4-part differently on different platforms. IPv4-part differently on different platforms.
*/ */
template<> bool Inet6::ascii_to_fbt(const char *str, size_t str_length)
bool Inet6Bundle::Fbt::ascii_to_fbt(const char *str, size_t str_length)
{ {
if (str_length < 2) if (str_length < 2)
{ {
...@@ -382,8 +381,7 @@ size_t Inet4::to_string(char *dst, size_t dstsize) const ...@@ -382,8 +381,7 @@ size_t Inet4::to_string(char *dst, size_t dstsize) const
Windows Vista, but out the minimum supported version is Windows 2000. Windows Vista, but out the minimum supported version is Windows 2000.
*/ */
template<> size_t Inet6::to_string(char *dst, size_t dstsize) const
size_t Inet6Bundle::Fbt::to_string(char *dst, size_t dstsize) const
{ {
struct Region struct Region
{ {
...@@ -509,8 +507,7 @@ size_t Inet6Bundle::Fbt::to_string(char *dst, size_t dstsize) const ...@@ -509,8 +507,7 @@ size_t Inet6Bundle::Fbt::to_string(char *dst, size_t dstsize) const
return (size_t) (p - dst); return (size_t) (p - dst);
} }
template<> const Name &Inet6::default_value()
const Name &Inet6Bundle::Type_handler_fbt::default_value() const
{ {
static Name def(STRING_WITH_LEN("::")); static Name def(STRING_WITH_LEN("::"));
return def; return def;
......
...@@ -31,8 +31,20 @@ static const size_t IN6_ADDR_NUM_WORDS= IN6_ADDR_SIZE / 2; ...@@ -31,8 +31,20 @@ static const size_t IN6_ADDR_NUM_WORDS= IN6_ADDR_SIZE / 2;
*/ */
static const uint IN6_ADDR_MAX_CHAR_LENGTH= 8 * 4 + 7; static const uint IN6_ADDR_MAX_CHAR_LENGTH= 8 * 4 + 7;
#include "sql_type_fixedbin_storage.h"
class Inet6: public FixedBinTypeStorage<IN6_ADDR_SIZE, IN6_ADDR_MAX_CHAR_LENGTH>
{
public:
using FixedBinTypeStorage::FixedBinTypeStorage;
bool ascii_to_fbt(const char *str, size_t str_length);
size_t to_string(char *dst, size_t dstsize) const;
static const Name &default_value();
};
#include "sql_type_fixedbin.h" #include "sql_type_fixedbin.h"
typedef FixedBinTypeBundle<IN6_ADDR_SIZE, IN6_ADDR_MAX_CHAR_LENGTH> Inet6Bundle; typedef FixedBinTypeBundle<Inet6> Inet6Bundle;
/***********************************************************************/ /***********************************************************************/
......
CREATE TABLE t1 (a UUID); CREATE TABLE t1 (a UUID);
Field 1: `a` Field 1: `a`
Org_field: `a`
Catalog: `def` Catalog: `def`
Database: `test` Database: `test`
Table: `t1` Table: `t1`
......
...@@ -42,8 +42,7 @@ static bool get_digit(char ch, uint *val) ...@@ -42,8 +42,7 @@ static bool get_digit(char ch, uint *val)
} }
template<> bool UUID::ascii_to_fbt(const char *str, size_t str_length)
bool UUIDBundle::Fbt::ascii_to_fbt(const char *str, size_t str_length)
{ {
if (str_length < 32 || str_length > 3 * binary_length() - 1) if (str_length < 32 || str_length > 3 * binary_length() - 1)
return true; return true;
...@@ -71,16 +70,14 @@ bool UUIDBundle::Fbt::ascii_to_fbt(const char *str, size_t str_length) ...@@ -71,16 +70,14 @@ bool UUIDBundle::Fbt::ascii_to_fbt(const char *str, size_t str_length)
return true; return true;
} }
template<> size_t UUID::to_string(char *dst, size_t dstsize) const
size_t UUIDBundle::Fbt::to_string(char *dst, size_t dstsize) const
{ {
my_uuid2str((const uchar *) m_buffer, dst, 1); my_uuid2str((const uchar *) m_buffer, dst, 1);
return MY_UUID_STRING_LENGTH; return MY_UUID_STRING_LENGTH;
} }
template<> const Name &UUID::default_value()
const Name &UUIDBundle::Type_handler_fbt::default_value() const
{ {
static Name def(STRING_WITH_LEN("00000000-0000-0000-0000-000000000000")); static Name def(STRING_WITH_LEN("00000000-0000-0000-0000-000000000000"));
return def; return def;
......
...@@ -16,7 +16,17 @@ ...@@ -16,7 +16,17 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#include "sql_type_fixedbin_storage.h"
class UUID: public FixedBinTypeStorage<MY_UUID_SIZE, MY_UUID_STRING_LENGTH>
{
public:
using FixedBinTypeStorage::FixedBinTypeStorage;
bool ascii_to_fbt(const char *str, size_t str_length);
size_t to_string(char *dst, size_t dstsize) const;
static const Name &default_value();
};
#include "sql_type_fixedbin.h" #include "sql_type_fixedbin.h"
typedef FixedBinTypeBundle<MY_UUID_SIZE, MY_UUID_STRING_LENGTH> UUIDBundle; typedef FixedBinTypeBundle<UUID> UUIDBundle;
#endif // SQL_TYPE_UUID_INCLUDED #endif // SQL_TYPE_UUID_INCLUDED
This diff is collapsed.
#ifndef SQL_TYPE_FIXEDBIN_STORAGE
#define SQL_TYPE_FIXEDBIN_STORAGE
/* Copyright (c) 2019,2021 MariaDB Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/*
This is a common code for plugin (?) types that are generally
handled like strings, but have their own fixed size on-disk binary storage
format and their own (variable size) canonical string representation.
Examples are INET6 and UUID types.
*/
/***********************************************************************/
template<size_t NATIVE_LEN, size_t MAX_CHAR_LEN>
class FixedBinTypeStorage
{
protected:
char m_buffer[NATIVE_LEN];
// Non-initializing constructor
FixedBinTypeStorage()
{ }
FixedBinTypeStorage & set_zero()
{
bzero(&m_buffer, sizeof(m_buffer));
return *this;
}
public:
// Initialize from binary representation
FixedBinTypeStorage(const char *str, size_t length)
{
if (length != binary_length())
set_zero();
else
memcpy(&m_buffer, str, sizeof(m_buffer));
}
static constexpr uint binary_length() { return NATIVE_LEN; }
static constexpr uint max_char_length() { return MAX_CHAR_LEN; }
static bool only_zero_bytes(const char *ptr, size_t length)
{
for (uint i= 0 ; i < length; i++)
{
if (ptr[i] != 0)
return false;
}
return true;
}
};
#endif /* SQL_TYPE_FIXEDBIN_STORAGE */
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