Skip to content

Commit b310b6b

Browse files
committed
ndb
- remove need for MAX_XXX values in mysql server enums, ll the values that can be expected to be handled by condition pushdown are hardcoded. Only when asking for "is this type supported/expected?" can we expect "any" value for the type. This means the 'expecting' functions should return false for any type values it does not know about. - Since we know the max values for bitmask at compile time, use fixed size buffers to remove the need for extra mallocs when creating Ndb_expect_stack - revert the additiotn of MAX_XXX values on the three enums
1 parent 2296f90 commit b310b6b

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

include/mysql.h.pp

+2-4
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858
MYSQL_TYPE_BLOB=252,
5959
MYSQL_TYPE_VAR_STRING=253,
6060
MYSQL_TYPE_STRING=254,
61-
MYSQL_TYPE_GEOMETRY=255,
62-
MYSQL_NUM_FIELD_TYPES
61+
MYSQL_TYPE_GEOMETRY=255
6362
};
6463
enum mysql_enum_shutdown_level {
6564
SHUTDOWN_DEFAULT = 0,
@@ -103,8 +102,7 @@
103102
double max_value_dbl;
104103
};
105104
enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
106-
DECIMAL_RESULT,
107-
MYSQL_NUM_ITEM_RESULTS };
105+
DECIMAL_RESULT};
108106
typedef struct st_udf_args
109107
{
110108
unsigned int arg_count;

include/mysql_com.h

-10
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,7 @@ enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
315315
MYSQL_TYPE_BLOB=252,
316316
MYSQL_TYPE_VAR_STRING=253,
317317
MYSQL_TYPE_STRING=254,
318-
#ifndef MCP_BUG58075
319-
MYSQL_TYPE_GEOMETRY=255,
320-
MYSQL_NUM_FIELD_TYPES /* Always last */
321-
#else
322318
MYSQL_TYPE_GEOMETRY=255
323-
#endif
324319
};
325320

326321
/* For backward compatibility */
@@ -448,12 +443,7 @@ struct rand_struct {
448443
/* The following is for user defined functions */
449444

450445
enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
451-
#ifndef MCP_BUG58075
452-
DECIMAL_RESULT,
453-
MYSQL_NUM_ITEM_RESULTS /* Always last */ };
454-
#else
455446
DECIMAL_RESULT};
456-
#endif
457447

458448
typedef struct st_udf_args
459449
{

sql/ha_ndbcluster_cond.h

+32-12
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#pragma interface /* gcc class implementation */
2626
#endif
2727

28-
#define round_up_byte(size) ((size + 7) >> 3) << 3
29-
3028
typedef enum ndb_item_type {
3129
NDB_VALUE = 0, // Qualified more with Item::Type
3230
NDB_FIELD = 1, // Qualified from table definition
@@ -333,22 +331,23 @@ class Ndb_cond_stack : public Sql_alloc
333331
*/
334332
class Ndb_expect_stack : public Sql_alloc
335333
{
334+
static const uint MAX_EXPECT_ITEMS = Item::VIEW_FIXER_ITEM + 1;
335+
static const uint MAX_EXPECT_FIELD_TYPES = MYSQL_TYPE_GEOMETRY + 1;
336+
static const uint MAX_EXPECT_FIELD_RESULTS = DECIMAL_RESULT + 1;
336337
public:
337338
Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
338339
{
339-
// Allocate type checking bitmaps
340-
bitmap_init(&expect_mask,
341-
0, round_up_byte(Item::MAX_NUM_ITEMS), FALSE);
342-
bitmap_init(&expect_field_type_mask,
343-
0, round_up_byte(MYSQL_NUM_FIELD_TYPES), FALSE);
344-
bitmap_init(&expect_field_result_mask,
345-
0, round_up_byte(MYSQL_NUM_ITEM_RESULTS), FALSE);
340+
// Allocate type checking bitmaps using fixed size buffers
341+
// since max size is known at compile time
342+
bitmap_init(&expect_mask, m_expect_buf,
343+
MAX_EXPECT_ITEMS, FALSE);
344+
bitmap_init(&expect_field_type_mask, m_expect_field_type_buf,
345+
MAX_EXPECT_FIELD_TYPES, FALSE);
346+
bitmap_init(&expect_field_result_mask, m_expect_field_result_buf,
347+
MAX_EXPECT_FIELD_RESULTS, FALSE);
346348
};
347349
~Ndb_expect_stack()
348350
{
349-
bitmap_free(&expect_mask);
350-
bitmap_free(&expect_field_type_mask);
351-
bitmap_free(&expect_field_result_mask);
352351
if (next)
353352
delete next;
354353
next= NULL;
@@ -385,6 +384,11 @@ Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
385384
}
386385
bool expecting(Item::Type type)
387386
{
387+
if (unlikely((uint)type > MAX_EXPECT_ITEMS))
388+
{
389+
// Unknown type, can't be expected
390+
return false;
391+
}
388392
return bitmap_is_set(&expect_mask, (uint) type);
389393
}
390394
void expect_nothing()
@@ -411,6 +415,11 @@ Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
411415
}
412416
bool expecting_field_type(enum_field_types type)
413417
{
418+
if (unlikely((uint)type > MAX_EXPECT_FIELD_TYPES))
419+
{
420+
// Unknown type, can't be expected
421+
return false;
422+
}
414423
return bitmap_is_set(&expect_field_type_mask, (uint) type);
415424
}
416425
void expect_no_field_type()
@@ -433,6 +442,11 @@ Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
433442
}
434443
bool expecting_field_result(Item_result result)
435444
{
445+
if (unlikely((uint)result > MAX_EXPECT_FIELD_RESULTS))
446+
{
447+
// Unknown result, can't be expected
448+
return false;
449+
}
436450
return bitmap_is_set(&expect_field_result_mask,
437451
(uint) result);
438452
}
@@ -484,6 +498,12 @@ Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
484498
}
485499

486500
private:
501+
my_bitmap_map
502+
m_expect_buf[bitmap_buffer_size(MAX_EXPECT_ITEMS)];
503+
my_bitmap_map
504+
m_expect_field_type_buf[bitmap_buffer_size(MAX_EXPECT_FIELD_TYPES)];
505+
my_bitmap_map
506+
m_expect_field_result_buf[bitmap_buffer_size(MAX_EXPECT_FIELD_RESULTS)];
487507
MY_BITMAP expect_mask;
488508
MY_BITMAP expect_field_type_mask;
489509
MY_BITMAP expect_field_result_mask;

sql/item.h

-5
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,7 @@ class Item {
490490
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
491491
PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
492492
XPATH_NODESET, XPATH_NODESET_CMP,
493-
#ifndef MCP_BUG58075
494-
VIEW_FIXER_ITEM,
495-
MAX_NUM_ITEMS /* Always last */
496-
#else
497493
VIEW_FIXER_ITEM
498-
#endif
499494
};
500495

501496
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };

sql/rpl_utility.cc

-2
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,6 @@ can_convert_field_to(Field *field,
736736
case MYSQL_TYPE_NULL:
737737
case MYSQL_TYPE_ENUM:
738738
case MYSQL_TYPE_SET:
739-
740-
case MYSQL_NUM_FIELD_TYPES:
741739
DBUG_RETURN(false);
742740
}
743741
DBUG_RETURN(false); // To keep GCC happy

0 commit comments

Comments
 (0)