Skip to content

Commit 0e8544c

Browse files
committed
MDEV-29355 Backport templatized INET6 implementation from 10.7 to 10.6
1 parent 4feb9df commit 0e8544c

File tree

9 files changed

+2174
-2112
lines changed

9 files changed

+2174
-2112
lines changed

plugin/type_inet/item_inetfunc.cc

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ String *Item_func_inet6_aton::val_str(String *buffer)
158158
return buffer;
159159
}
160160

161-
Inet6_null ipv6(*tmp.string());
161+
Inet6Bundle::Fbt_null ipv6(*tmp.string());
162162
if (!ipv6.is_null())
163163
{
164164
ipv6.to_binary(buffer);
@@ -197,7 +197,7 @@ String *Item_func_inet6_ntoa::val_str_ascii(String *buffer)
197197
return buffer;
198198
}
199199

200-
Inet6_null ipv6(static_cast<const Binary_string&>(*tmp.string()));
200+
Inet6Bundle::Fbt_null ipv6(static_cast<const Binary_string&>(*tmp.string()));
201201
if (!ipv6.is_null())
202202
{
203203
ipv6.to_string(buffer);
@@ -221,6 +221,22 @@ longlong Item_func_is_ipv4::val_int()
221221
return !tmp.is_null() && !Inet4_null(*tmp.string()).is_null();
222222
}
223223

224+
class IP6 : public Inet6Bundle::Fbt_null
225+
{
226+
public:
227+
IP6(Item* arg) : Inet6Bundle::Fbt_null(arg) {}
228+
bool is_v4compat() const
229+
{
230+
static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size");
231+
return IN6_IS_ADDR_V4COMPAT((struct in6_addr *) m_buffer);
232+
}
233+
bool is_v4mapped() const
234+
{
235+
static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size");
236+
return IN6_IS_ADDR_V4MAPPED((struct in6_addr *) m_buffer);
237+
}
238+
};
239+
224240

225241
/**
226242
Checks if the passed string represents an IPv6-address.
@@ -230,17 +246,16 @@ longlong Item_func_is_ipv6::val_int()
230246
{
231247
DBUG_ASSERT(fixed());
232248
String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]);
233-
return !tmp.is_null() && !Inet6_null(*tmp.string()).is_null();
249+
return !tmp.is_null() && !Inet6Bundle::Fbt_null(*tmp.string()).is_null();
234250
}
235251

236-
237252
/**
238253
Checks if the passed IPv6-address is an IPv4-compat IPv6-address.
239254
*/
240255

241256
longlong Item_func_is_ipv4_compat::val_int()
242257
{
243-
Inet6_null ip6(args[0]);
258+
IP6 ip6(args[0]);
244259
return !ip6.is_null() && ip6.is_v4compat();
245260
}
246261

@@ -251,6 +266,6 @@ longlong Item_func_is_ipv4_compat::val_int()
251266

252267
longlong Item_func_is_ipv4_mapped::val_int()
253268
{
254-
Inet6_null ip6(args[0]);
269+
IP6 ip6(args[0]);
255270
return !ip6.is_null() && ip6.is_v4mapped();
256271
}

plugin/type_inet/mysql-test/type_inet/type_inet6.result

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,3 +2229,31 @@ SELECT * FROM t1 WHERE d >= ALL (SELECT * FROM t1);
22292229
d
22302230
12::
22312231
DROP TABLE t1;
2232+
#
2233+
# MDEV-27015 Assertion `!is_null()' failed in FixedBinTypeBundle<FbtImpl>::Fbt FixedBinTypeBundle<FbtImpl>::Field_fbt::to_fbt()
2234+
#
2235+
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a INET6(6) DEFAULT '::10');
2236+
INSERT INTO t1(id) VALUES (1), (2), (3), (4);
2237+
INSERT INTO t1 VALUES (5,'::5'), (6,'::6');
2238+
SELECT * FROM t1 ORDER BY a;
2239+
id a
2240+
5 ::5
2241+
6 ::6
2242+
1 ::10
2243+
2 ::10
2244+
3 ::10
2245+
4 ::10
2246+
CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a;
2247+
CREATE TABLE t2 SELECT * FROM v1;
2248+
SELECT * FROM v1 ORDER BY a;
2249+
a m
2250+
::5 5
2251+
::6 6
2252+
::10 1
2253+
SELECT * FROM t2 ORDER BY a;
2254+
a m
2255+
::5 5
2256+
::6 6
2257+
::10 1
2258+
DROP VIEW v1;
2259+
DROP TABLE t1, t2;

plugin/type_inet/mysql-test/type_inet/type_inet6.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,3 +1641,18 @@ SELECT * FROM t1 ORDER BY d;
16411641
SELECT * FROM t1 WHERE d <= ALL (SELECT * FROM t1);
16421642
SELECT * FROM t1 WHERE d >= ALL (SELECT * FROM t1);
16431643
DROP TABLE t1;
1644+
1645+
--echo #
1646+
--echo # MDEV-27015 Assertion `!is_null()' failed in FixedBinTypeBundle<FbtImpl>::Fbt FixedBinTypeBundle<FbtImpl>::Field_fbt::to_fbt()
1647+
--echo #
1648+
1649+
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a INET6(6) DEFAULT '::10');
1650+
INSERT INTO t1(id) VALUES (1), (2), (3), (4);
1651+
INSERT INTO t1 VALUES (5,'::5'), (6,'::6');
1652+
SELECT * FROM t1 ORDER BY a;
1653+
CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a;
1654+
CREATE TABLE t2 SELECT * FROM v1;
1655+
SELECT * FROM v1 ORDER BY a;
1656+
SELECT * FROM t2 ORDER BY a;
1657+
DROP VIEW v1;
1658+
DROP TABLE t1, t2;

plugin/type_inet/plugin.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019 MariaDB Corporation
1+
/* Copyright (c) 2019,2021 MariaDB Corporation
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -21,14 +21,10 @@
2121
#include <mysql/plugin_data_type.h>
2222
#include <mysql/plugin_function.h>
2323

24-
25-
Type_handler_inet6 type_handler_inet6;
26-
27-
2824
static struct st_mariadb_data_type plugin_descriptor_type_inet6=
2925
{
3026
MariaDB_DATA_TYPE_INTERFACE_VERSION,
31-
&type_handler_inet6
27+
Inet6Bundle::type_handler_fbt()
3228
};
3329

3430

0 commit comments

Comments
 (0)