24 typedef enum ndb_item_type {
 
   31 typedef enum ndb_func_type {
 
   39   NDB_ISNOTNULL_FUNC = 7,
 
   43   NDB_UNKNOWN_FUNC = 11,
 
   44   NDB_COND_AND_FUNC = 12,
 
   45   NDB_COND_OR_FUNC = 13,
 
   46   NDB_UNSUPPORTED_FUNC = 14
 
   50   Item::Type value_type; 
 
   51   enum_field_types field_type; 
 
   52   NDB_FUNC_TYPE function_type; 
 
   68   NDB_FUNC_TYPE pos_fun;
 
   69   NDB_FUNC_TYPE neg_fun;
 
   78   {NDB_EQ_FUNC, NDB_NE_FUNC},
 
   79   {NDB_NE_FUNC, NDB_EQ_FUNC},
 
   80   {NDB_LT_FUNC, NDB_GE_FUNC},
 
   81   {NDB_LE_FUNC, NDB_GT_FUNC},
 
   82   {NDB_GT_FUNC, NDB_LE_FUNC},
 
   83   {NDB_GE_FUNC, NDB_LT_FUNC},
 
   84   {NDB_ISNULL_FUNC, NDB_ISNOTNULL_FUNC},
 
   85   {NDB_ISNOTNULL_FUNC, NDB_ISNULL_FUNC},
 
   86   {NDB_LIKE_FUNC, NDB_NOTLIKE_FUNC},
 
   87   {NDB_NOTLIKE_FUNC, NDB_LIKE_FUNC},
 
   88   {NDB_NOT_FUNC, NDB_UNSUPPORTED_FUNC},
 
   89   {NDB_UNKNOWN_FUNC, NDB_UNSUPPORTED_FUNC},
 
   90   {NDB_COND_AND_FUNC, NDB_UNSUPPORTED_FUNC},
 
   91   {NDB_COND_OR_FUNC, NDB_UNSUPPORTED_FUNC},
 
   92   {NDB_UNSUPPORTED_FUNC, NDB_UNSUPPORTED_FUNC}
 
  111   Ndb_item(NDB_ITEM_TYPE item_type) : type(item_type) {};
 
  114            const Item *item_value)
 
  115     : type(item_type), qualification(item_qualification)
 
  119       value.item= item_value;
 
  124       field_value->field= field_item->field;
 
  125       field_value->column_no= -1; 
 
  126       value.field_value= field_value;
 
  130       value.item= item_value;
 
  131       value.arg_count= ((
Item_func *) item_value)->argument_count();
 
  140     qualification.field_type= field->real_type();
 
  141     field_value->field= field;
 
  142     field_value->column_no= column_no;
 
  143     value.field_value= field_value;
 
  145   Ndb_item(Item_func::Functype func_type, 
const Item *item_value) 
 
  148     qualification.function_type= item_func_to_ndb_func(func_type);
 
  149     value.item= item_value;
 
  150     value.arg_count= ((
Item_func *) item_value)->argument_count();
 
  152   Ndb_item(Item_func::Functype func_type, uint no_args) 
 
  155     qualification.function_type= item_func_to_ndb_func(func_type);
 
  156     value.arg_count= no_args;
 
  160     if (type == NDB_FIELD)
 
  162         delete value.field_value;
 
  163         value.field_value= NULL;
 
  171       if(qualification.value_type == Item::STRING_ITEM)
 
  172         return value.item->str_value.length();
 
  175       return value.field_value->field->pack_length(); 
 
  183   Field * get_field() { 
return value.field_value->field; };
 
  185   int get_field_no() { 
return value.field_value->column_no; };
 
  189     return value.arg_count;
 
  192   const char* get_val() 
 
  196       if(qualification.value_type == Item::STRING_ITEM)
 
  197         return value.item->str_value.ptr();
 
  200       return (
char*) value.field_value->field->ptr; 
 
  208   void save_in_field(
Ndb_item *field_item)
 
  210     DBUG_ENTER(
"save_in_field");
 
  211     Field *field = field_item->value.field_value->field;
 
  212     const Item *item= value.item;
 
  215       DBUG_PRINT(
"info", (
"item length %u, field length %u",
 
  216                           item->max_length, field->field_length));
 
  217       if (item->max_length > field->field_length)
 
  219         DBUG_PRINT(
"info", (
"Comparing field with longer value"));
 
  220         DBUG_PRINT(
"info", (
"Field can store %u", field->field_length));
 
  222       my_bitmap_map *old_map=
 
  223         dbug_tmp_use_all_columns(field->table, field->table->write_set);
 
  224       ((
Item *)item)->save_in_field(field, FALSE);
 
  225       dbug_tmp_restore_column_map(field->table->write_set, old_map);
 
  230   static NDB_FUNC_TYPE item_func_to_ndb_func(Item_func::Functype fun)
 
  233     case (Item_func::EQ_FUNC): { 
return NDB_EQ_FUNC; }
 
  234     case (Item_func::NE_FUNC): { 
return NDB_NE_FUNC; }
 
  235     case (Item_func::LT_FUNC): { 
return NDB_LT_FUNC; }
 
  236     case (Item_func::LE_FUNC): { 
return NDB_LE_FUNC; }
 
  237     case (Item_func::GT_FUNC): { 
return NDB_GT_FUNC; }
 
  238     case (Item_func::GE_FUNC): { 
return NDB_GE_FUNC; }
 
  239     case (Item_func::ISNULL_FUNC): { 
return NDB_ISNULL_FUNC; }
 
  240     case (Item_func::ISNOTNULL_FUNC): { 
return NDB_ISNOTNULL_FUNC; }
 
  241     case (Item_func::LIKE_FUNC): { 
return NDB_LIKE_FUNC; }
 
  242     case (Item_func::NOT_FUNC): { 
return NDB_NOT_FUNC; }
 
  243     case (Item_func::NEG_FUNC): { 
return NDB_UNKNOWN_FUNC; }
 
  244     case (Item_func::UNKNOWN_FUNC): { 
return NDB_UNKNOWN_FUNC; }
 
  245     case (Item_func::COND_AND_FUNC): { 
return NDB_COND_AND_FUNC; }
 
  246     case (Item_func::COND_OR_FUNC): { 
return NDB_COND_OR_FUNC; }
 
  247     default: { 
return NDB_UNSUPPORTED_FUNC; }
 
  251   static NDB_FUNC_TYPE negate(NDB_FUNC_TYPE fun)
 
  254     DBUG_ASSERT(fun == neg_map[i].pos_fun);
 
  255     return  neg_map[
i].neg_fun;
 
  271   Ndb_cond() : ndb_item(NULL), next(NULL), prev(NULL) {};
 
  274     if (ndb_item) 
delete ndb_item; 
 
  309     if (ndb_cond) 
delete ndb_cond; 
 
  311     if (next) 
delete next;
 
  330   static const uint MAX_EXPECT_ITEMS = Item::VIEW_FIXER_ITEM + 1;
 
  331   static const uint MAX_EXPECT_FIELD_TYPES = MYSQL_TYPE_GEOMETRY + 1;
 
  332   static const uint MAX_EXPECT_FIELD_RESULTS = DECIMAL_RESULT + 1;
 
  338     bitmap_init(&expect_mask, m_expect_buf,
 
  339                 MAX_EXPECT_ITEMS, FALSE);
 
  340     bitmap_init(&expect_field_type_mask, m_expect_field_type_buf,
 
  341                 MAX_EXPECT_FIELD_TYPES, FALSE);
 
  342     bitmap_init(&expect_field_result_mask, m_expect_field_result_buf,
 
  343                 MAX_EXPECT_FIELD_RESULTS, FALSE);
 
  360       bitmap_clear_all(&expect_mask);
 
  361       bitmap_union(&expect_mask, &next->expect_mask);
 
  362       bitmap_clear_all(&expect_field_type_mask);
 
  363       bitmap_union(&expect_field_type_mask, &next->expect_field_type_mask);
 
  364       bitmap_clear_all(&expect_field_result_mask);
 
  365       bitmap_union(&expect_field_result_mask, &next->expect_field_result_mask);
 
  366       collation= next->collation;
 
  371   void expect(Item::Type 
type)
 
  373     bitmap_set_bit(&expect_mask, (uint) type);
 
  374     if (type == Item::FIELD_ITEM)
 
  375       expect_all_field_types();
 
  377   void dont_expect(Item::Type type)
 
  379     bitmap_clear_bit(&expect_mask, (uint) type);
 
  381   bool expecting(Item::Type type)
 
  383     if (unlikely((uint)type > MAX_EXPECT_ITEMS))
 
  388     return bitmap_is_set(&expect_mask, (uint) type);
 
  390   void expect_nothing()
 
  392     bitmap_clear_all(&expect_mask);
 
  394   bool expecting_nothing()
 
  396     return bitmap_is_clear_all(&expect_mask);
 
  398   void expect_only(Item::Type type)
 
  404   void expect_field_type(enum_field_types type)
 
  406     bitmap_set_bit(&expect_field_type_mask, (uint) type);
 
  408   void expect_all_field_types()
 
  410     bitmap_set_all(&expect_field_type_mask);
 
  412   bool expecting_field_type(enum_field_types type)
 
  414     if (unlikely((uint)type > MAX_EXPECT_FIELD_TYPES))
 
  419     return bitmap_is_set(&expect_field_type_mask, (uint) type);
 
  421   void expect_no_field_type()
 
  423     bitmap_clear_all(&expect_field_type_mask);
 
  425   bool expecting_no_field_type()
 
  427     return bitmap_is_clear_all(&expect_field_type_mask);
 
  429   void expect_only_field_type(enum_field_types result)
 
  431     expect_no_field_type();
 
  432     expect_field_type(result);
 
  435   void expect_field_result(Item_result result)
 
  437     bitmap_set_bit(&expect_field_result_mask, (uint) result);
 
  439   bool expecting_field_result(Item_result result)
 
  441     if (unlikely((uint)result > MAX_EXPECT_FIELD_RESULTS))
 
  446     return bitmap_is_set(&expect_field_result_mask,
 
  449   void expect_no_field_result()
 
  451     bitmap_clear_all(&expect_field_result_mask);
 
  453   bool expecting_no_field_result()
 
  455     return bitmap_is_clear_all(&expect_field_result_mask);
 
  457   void expect_only_field_result(Item_result result)
 
  459     expect_no_field_result();
 
  460     expect_field_result(result);
 
  468     bool matching= (!collation)
 
  470       : (collation == col);
 
  475   void expect_length(Uint32 len)
 
  479   void expect_max_length(Uint32 max)
 
  483   bool expecting_length(Uint32 len)
 
  485     return max_length == 0 || len <= max_length;
 
  487   bool expecting_max_length(Uint32 max)
 
  489     return max >= length;
 
  491   void expect_no_length()
 
  493     length= max_length= 0;
 
  498     m_expect_buf[bitmap_buffer_size(MAX_EXPECT_ITEMS)];
 
  500     m_expect_field_type_buf[bitmap_buffer_size(MAX_EXPECT_FIELD_TYPES)];
 
  502     m_expect_field_result_buf[bitmap_buffer_size(MAX_EXPECT_FIELD_RESULTS)];
 
  516     : func_item(func), left_hand_item(NULL), count(0) {};
 
  519     if (next) 
delete next;
 
  522   const Item *left_hand_item;
 
  539     : table(tab), ndb_table(ndb_tab), 
 
  540     supported(TRUE), cond_stack(stack), cond_ptr(NULL),
 
  541     skip(0), rewrite_stack(NULL)
 
  544       cond_ptr= stack->ndb_cond;
 
  548     if (rewrite_stack) 
delete rewrite_stack;
 
  550   inline void expect(Item::Type 
type)
 
  552     expect_stack.expect(type);
 
  554   inline void dont_expect(Item::Type type)
 
  556     expect_stack.dont_expect(type);
 
  558   inline bool expecting(Item::Type type)
 
  560     return expect_stack.expecting(type);
 
  562   inline void expect_nothing()
 
  564     expect_stack.expect_nothing();
 
  566   inline bool expecting_nothing()
 
  568     return expect_stack.expecting_nothing();
 
  570   inline void expect_only(Item::Type type)
 
  572     expect_stack.expect_only(type);
 
  575   inline void expect_field_type(enum_field_types type)
 
  577     expect_stack.expect_field_type(type);
 
  579   inline void expect_all_field_types()
 
  581     expect_stack.expect_all_field_types();
 
  583   inline bool expecting_field_type(enum_field_types type)
 
  585     return expect_stack.expecting_field_type(type);
 
  587   inline void expect_no_field_type()
 
  589     expect_stack.expect_no_field_type();
 
  591   inline bool expecting_no_field_type()
 
  593     return expect_stack.expecting_no_field_type();
 
  595   inline void expect_only_field_type(enum_field_types result)
 
  597     expect_stack.expect_only_field_type(result);
 
  600   inline void expect_field_result(Item_result result)
 
  602     expect_stack.expect_field_result(result);
 
  604   inline bool expecting_field_result(Item_result result)
 
  606     return expect_stack.expecting_field_result(result);
 
  608   inline void expect_no_field_result()
 
  610     expect_stack.expect_no_field_result();
 
  612   inline bool expecting_no_field_result()
 
  614     return expect_stack.expecting_no_field_result();
 
  616   inline void expect_only_field_result(Item_result result)
 
  618     expect_stack.expect_only_field_result(result);
 
  622     expect_stack.expect_collation(col);
 
  624   inline bool expecting_collation(
const CHARSET_INFO* col)
 
  626     return expect_stack.expecting_collation(col);
 
  628   inline void expect_length(Uint32 length)
 
  630     expect_stack.expect_length(length);
 
  632   inline void expect_max_length(Uint32 max)
 
  634     expect_stack.expect_max_length(max);
 
  636   inline bool expecting_length(Uint32 length)
 
  638     return expect_stack.expecting_length(length);
 
  640   inline bool expecting_max_length(Uint32 max)
 
  642     return expect_stack.expecting_max_length(max);
 
  644   inline void expect_no_length()
 
  646     expect_stack.expect_no_length();
 
  669   { 
if (m_cond_stack) 
delete m_cond_stack; }
 
  670   const Item *cond_push(
const Item *cond, 
 
  686   int build_scan_filter_predicate(
Ndb_cond* &cond, 
 
  688                                   bool negated= 
false);
 
  689   int build_scan_filter_group(
Ndb_cond* &cond,