Skip to content

Commit 506ffd0

Browse files
committed
Bug#25418534: JSON_EXTRACT USING WILDCARDS TAKES FOREVER
Patch #9: Inline json_binary::Value's constructors and getters. BM_JsonBinarySearchEllipsis 16817 [+21.7%] BM_JsonBinarySearchEllipsis_OnlyOne 70 [ +7.1%] BM_JsonBinarySearchKey 64 [ +4.7%] Change-Id: I5882869fd58caa7fd88f70e3e837ee5d2c4427d0
1 parent aa59d77 commit 506ffd0

File tree

2 files changed

+103
-143
lines changed

2 files changed

+103
-143
lines changed

sql/json_binary.cc

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -944,56 +944,6 @@ serialize_json_value(const THD *thd, const Json_dom *dom, size_t type_pos,
944944
}
945945

946946

947-
// Constructor for literals and errors.
948-
Value::Value(enum_type t)
949-
: m_data(nullptr), m_element_count(), m_length(), m_field_type(), m_type(t),
950-
m_large()
951-
{
952-
DBUG_ASSERT(t == LITERAL_NULL || t == LITERAL_TRUE || t == LITERAL_FALSE ||
953-
t == ERROR);
954-
}
955-
956-
957-
// Constructor for int and uint.
958-
Value::Value(enum_type t, int64 val)
959-
: m_int_value(val), m_element_count(), m_length(), m_field_type(), m_type(t),
960-
m_large()
961-
{
962-
DBUG_ASSERT(t == INT || t == UINT);
963-
}
964-
965-
966-
// Constructor for double.
967-
Value::Value(double d)
968-
: m_double_value(d), m_element_count(), m_length(), m_field_type(),
969-
m_type(DOUBLE), m_large()
970-
{}
971-
972-
973-
// Constructor for string.
974-
Value::Value(const char *data, uint32 len)
975-
: m_data(data), m_element_count(), m_length(len), m_field_type(),
976-
m_type(STRING), m_large()
977-
{}
978-
979-
980-
// Constructor for arrays and objects.
981-
Value::Value(enum_type t, const char *data, uint32 bytes,
982-
uint32 element_count, bool large)
983-
: m_data(data), m_element_count(element_count), m_length(bytes),
984-
m_field_type(), m_type(t), m_large(large)
985-
{
986-
DBUG_ASSERT(t == ARRAY || t == OBJECT);
987-
}
988-
989-
990-
// Constructor for opaque values.
991-
Value::Value(enum_field_types ft, const char *data, uint32 len)
992-
: m_data(data), m_element_count(), m_length(len), m_field_type(ft),
993-
m_type(OPAQUE), m_large()
994-
{}
995-
996-
997947
bool Value::is_valid() const
998948
{
999949
switch (m_type)
@@ -1041,80 +991,6 @@ bool Value::is_valid() const
1041991
}
1042992

1043993

1044-
/**
1045-
Get a pointer to the beginning of the STRING or OPAQUE data
1046-
represented by this instance.
1047-
*/
1048-
const char *Value::get_data() const
1049-
{
1050-
DBUG_ASSERT(m_type == STRING || m_type == OPAQUE);
1051-
return m_data;
1052-
}
1053-
1054-
1055-
/**
1056-
Get the length in bytes of the STRING or OPAQUE value represented by
1057-
this instance.
1058-
*/
1059-
uint32 Value::get_data_length() const
1060-
{
1061-
DBUG_ASSERT(m_type == STRING || m_type == OPAQUE);
1062-
return m_length;
1063-
}
1064-
1065-
1066-
/**
1067-
Get the value of an INT.
1068-
*/
1069-
int64 Value::get_int64() const
1070-
{
1071-
DBUG_ASSERT(m_type == INT);
1072-
return m_int_value;
1073-
}
1074-
1075-
1076-
/**
1077-
Get the value of a UINT.
1078-
*/
1079-
uint64 Value::get_uint64() const
1080-
{
1081-
DBUG_ASSERT(m_type == UINT);
1082-
return static_cast<uint64>(m_int_value);
1083-
}
1084-
1085-
1086-
/**
1087-
Get the value of a DOUBLE.
1088-
*/
1089-
double Value::get_double() const
1090-
{
1091-
DBUG_ASSERT(m_type == DOUBLE);
1092-
return m_double_value;
1093-
}
1094-
1095-
1096-
/**
1097-
Get the number of elements in an array, or the number of members in
1098-
an object.
1099-
*/
1100-
uint32 Value::element_count() const
1101-
{
1102-
DBUG_ASSERT(m_type == ARRAY || m_type == OBJECT);
1103-
return m_element_count;
1104-
}
1105-
1106-
1107-
/**
1108-
Get the MySQL field type of an opaque value. Identifies the type of
1109-
the value stored in the data portion of an opaque value.
1110-
*/
1111-
enum_field_types Value::field_type() const
1112-
{
1113-
DBUG_ASSERT(m_type == OPAQUE);
1114-
return m_field_type;
1115-
}
1116-
1117-
1118994
/**
1119995
Create a Value object that represents an error condition.
1120996
*/

sql/json_binary.h

Lines changed: 103 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
#include <string>
139139

140140
#include "binary_log_types.h" // enum_field_types
141+
#include "my_dbug.h" // DBUG_ASSERT
141142
#include "my_inttypes.h"
142143

143144
class Field_json;
@@ -190,15 +191,70 @@ class Value
190191
enum_type type() const { return m_type; }
191192
/// Does this value use the large storage format?
192193
bool large_format() const { return m_large; }
193-
const char *get_data() const;
194-
uint32 get_data_length() const;
195-
int64 get_int64() const;
196-
uint64 get_uint64() const;
197-
double get_double() const;
198-
uint32 element_count() const;
194+
195+
/**
196+
Get a pointer to the beginning of the STRING or OPAQUE data
197+
represented by this instance.
198+
*/
199+
const char *get_data() const
200+
{
201+
DBUG_ASSERT(m_type == STRING || m_type == OPAQUE);
202+
return m_data;
203+
}
204+
205+
/**
206+
Get the length in bytes of the STRING or OPAQUE value represented by
207+
this instance.
208+
*/
209+
uint32 get_data_length() const
210+
{
211+
DBUG_ASSERT(m_type == STRING || m_type == OPAQUE);
212+
return m_length;
213+
}
214+
215+
/** Get the value of an INT. */
216+
int64 get_int64() const
217+
{
218+
DBUG_ASSERT(m_type == INT);
219+
return m_int_value;
220+
}
221+
222+
/** Get the value of a UINT. */
223+
uint64 get_uint64() const
224+
{
225+
DBUG_ASSERT(m_type == UINT);
226+
return static_cast<uint64>(m_int_value);
227+
}
228+
229+
/** Get the value of a DOUBLE. */
230+
double get_double() const
231+
{
232+
DBUG_ASSERT(m_type == DOUBLE);
233+
return m_double_value;
234+
}
235+
236+
/**
237+
Get the number of elements in an array, or the number of members in
238+
an object.
239+
*/
240+
uint32 element_count() const
241+
{
242+
DBUG_ASSERT(m_type == ARRAY || m_type == OBJECT);
243+
return m_element_count;
244+
}
245+
246+
/**
247+
Get the MySQL field type of an opaque value. Identifies the type of
248+
the value stored in the data portion of an opaque value.
249+
*/
250+
enum_field_types field_type() const
251+
{
252+
DBUG_ASSERT(m_type == OPAQUE);
253+
return m_field_type;
254+
}
255+
199256
Value element(size_t pos) const;
200257
Value key(size_t pos) const;
201-
enum_field_types field_type() const;
202258
Value lookup(const std::string &key) const;
203259
size_t lookup_index(const std::string &key) const;
204260
bool is_backed_by(const String *str) const;
@@ -213,27 +269,50 @@ class Value
213269
const char *original, char *destination) const;
214270

215271
/** Constructor for values that represent literals or errors. */
216-
explicit Value(enum_type t);
272+
explicit Value(enum_type t)
273+
: m_data(nullptr), m_type(t)
274+
{
275+
DBUG_ASSERT(t == LITERAL_NULL || t == LITERAL_TRUE || t == LITERAL_FALSE ||
276+
t == ERROR);
277+
}
278+
217279
/** Constructor for values that represent ints or uints. */
218-
explicit Value(enum_type t, int64 val);
280+
explicit Value(enum_type t, int64 val)
281+
: m_int_value(val), m_type(t)
282+
{
283+
DBUG_ASSERT(t == INT || t == UINT);
284+
}
285+
219286
/** Constructor for values that represent doubles. */
220-
explicit Value(double val);
287+
explicit Value(double val) : m_double_value(val), m_type(DOUBLE) {}
288+
221289
/** Constructor for values that represent strings. */
222-
Value(const char *data, uint32 len);
290+
Value(const char *data, uint32 len)
291+
: m_data(data), m_length(len), m_type(STRING)
292+
{}
293+
223294
/**
224295
Constructor for values that represent arrays or objects.
225296
226297
@param t type
227298
@param data pointer to the start of the binary representation
228-
@param element_count the number of elements or members in the value
229299
@param bytes the number of bytes in the binary representation of the value
300+
@param element_count the number of elements or members in the value
230301
@param large true if the value should be stored in the large
231302
storage format with 4 byte offsets instead of 2 byte offsets
232303
*/
233-
Value(enum_type t, const char *data, uint32 element_count, uint32 bytes,
234-
bool large);
304+
Value(enum_type t, const char *data, uint32 bytes, uint32 element_count,
305+
bool large)
306+
: m_data(data), m_element_count(element_count), m_length(bytes),
307+
m_type(t), m_large(large)
308+
{
309+
DBUG_ASSERT(t == ARRAY || t == OBJECT);
310+
}
311+
235312
/** Constructor for values that represent opaque data. */
236-
Value(enum_field_types ft, const char *data, uint32 len);
313+
Value(enum_field_types ft, const char *data, uint32 len)
314+
: m_data(data), m_length(len), m_field_type(ft), m_type(OPAQUE)
315+
{}
237316

238317
/** Empty constructor. Produces a value that represents an error condition. */
239318
Value() : Value(ERROR) {}
@@ -276,27 +355,32 @@ class Value
276355
/** The value if the type is DOUBLE. */
277356
const double m_double_value;
278357
};
358+
279359
/**
280360
Element count for arrays and objects. Unused for other types.
281361
*/
282-
const uint32 m_element_count;
362+
const uint32 m_element_count{};
363+
283364
/**
284365
The full length (in bytes) of the binary representation of an array or
285366
object, or the length of a string or opaque value. Unused for other types.
286367
*/
287-
const uint32 m_length;
368+
const uint32 m_length{};
369+
288370
/**
289371
The MySQL field type of the value, in case the type of the value is
290372
OPAQUE. Otherwise, it is unused.
291373
*/
292-
const enum_field_types m_field_type;
374+
const enum_field_types m_field_type{};
375+
293376
/** The JSON type of the value. */
294377
const enum_type m_type;
378+
295379
/**
296380
True if an array or an object uses the large storage format with 4
297381
byte offsets instead of 2 byte offsets.
298382
*/
299-
const bool m_large;
383+
const bool m_large{};
300384

301385
size_t key_entry_offset(size_t pos) const;
302386
size_t value_entry_offset(size_t pos) const;

0 commit comments

Comments
 (0)