~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/handler.h

  • Committer: Brian Aker
  • Date: 2008-07-11 00:33:12 UTC
  • mfrom: (51.1.83 remove-dbug)
  • Revision ID: brian@tangent.org-20080711003312-f4sf5n2z3obor1u8
Comming Jay's merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
605
605
    * stmt.modified_non_trans_table is used to keep track of
606
606
    modified non-transactional tables of top-level statements. At
607
607
    the end of the previous statement and at the beginning of the session,
608
 
    it is reset to FALSE.  If such functions
 
608
    it is reset to false.  If such functions
609
609
    as mysql_insert, mysql_update, mysql_delete etc modify a
610
 
    non-transactional table, they set this flag to TRUE.  At the
 
610
    non-transactional table, they set this flag to true.  At the
611
611
    end of the statement, the value of stmt.modified_non_trans_table 
612
612
    is merged with all.modified_non_trans_table and gets reset.
613
613
    * all.modified_non_trans_table is reset at the end of transaction
618
618
    At entrance into a sub-statement, a copy of the value of
619
619
    stmt.modified_non_trans_table (containing the changes of the
620
620
    outer statement) is saved on stack. Then 
621
 
    stmt.modified_non_trans_table is reset to FALSE and the
 
621
    stmt.modified_non_trans_table is reset to false and the
622
622
    substatement is executed. Then the new value is merged with the
623
623
    saved value.
624
624
  */
625
625
  bool modified_non_trans_table;
626
626
 
627
 
  void reset() { no_2pc= FALSE; modified_non_trans_table= FALSE; }
 
627
  void reset() { no_2pc= false; modified_non_trans_table= false; }
628
628
};
629
629
 
630
630
 
651
651
  /** Register this storage engine in the given transaction context. */
652
652
  void register_ha(THD_TRANS *trans, handlerton *ht_arg)
653
653
  {
654
 
    DBUG_ASSERT(m_flags == 0);
655
 
    DBUG_ASSERT(m_ht == NULL);
656
 
    DBUG_ASSERT(m_next == NULL);
 
654
    assert(m_flags == 0);
 
655
    assert(m_ht == NULL);
 
656
    assert(m_next == NULL);
657
657
 
658
658
    m_ht= ht_arg;
659
659
    m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
674
674
 
675
675
  void set_trx_read_write()
676
676
  {
677
 
    DBUG_ASSERT(is_started());
 
677
    assert(is_started());
678
678
    m_flags|= (int) TRX_READ_WRITE;
679
679
  }
680
680
  bool is_trx_read_write() const
681
681
  {
682
 
    DBUG_ASSERT(is_started());
 
682
    assert(is_started());
683
683
    return m_flags & (int) TRX_READ_WRITE;
684
684
  }
685
685
  bool is_started() const { return m_ht != NULL; }
691
691
      Can be called many times, e.g. when we have many
692
692
      read-write statements in a transaction.
693
693
    */
694
 
    DBUG_ASSERT(is_started());
 
694
    assert(is_started());
695
695
    if (stmt_trx->is_trx_read_write())
696
696
      set_trx_read_write();
697
697
  }
698
698
  Ha_trx_info *next() const
699
699
  {
700
 
    DBUG_ASSERT(is_started());
 
700
    assert(is_started());
701
701
    return m_next;
702
702
  }
703
703
  handlerton *ht() const
704
704
  {
705
 
    DBUG_ASSERT(is_started());
 
705
    assert(is_started());
706
706
    return m_ht;
707
707
  }
708
708
private:
1141
1141
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
1142
1142
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
1143
1143
  uint ranges_in_seq; /* Total number of ranges in the traversed sequence */
1144
 
  /* TRUE <=> source MRR ranges and the output are ordered */
 
1144
  /* true <=> source MRR ranges and the output are ordered */
1145
1145
  bool mrr_is_output_sorted;
1146
1146
 
1147
 
  /** TRUE <=> we're currently traversing a range in mrr_cur_range. */
 
1147
  /** true <=> we're currently traversing a range in mrr_cur_range. */
1148
1148
  bool mrr_have_range;
1149
1149
  /** Current range (the one we're now returning rows from) */
1150
1150
  KEY_MULTI_RANGE mrr_cur_range;
1155
1155
  int key_compare_result_on_equal;
1156
1156
  bool eq_range;
1157
1157
  /* 
1158
 
    TRUE <=> the engine guarantees that returned records are within the range
 
1158
    true <=> the engine guarantees that returned records are within the range
1159
1159
    being scanned.
1160
1160
  */
1161
1161
  bool in_range_check_pushed_down;
1200
1200
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
1201
1201
    :table_share(share_arg), table(0),
1202
1202
    estimation_rows_to_insert(0), ht(ht_arg),
1203
 
    ref(0), in_range_check_pushed_down(FALSE),
 
1203
    ref(0), in_range_check_pushed_down(false),
1204
1204
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
1205
1205
    ref_length(sizeof(my_off_t)),
1206
1206
    ft_handler(0), inited(NONE),
1207
 
    locked(FALSE), implicit_emptied(0),
 
1207
    locked(false), implicit_emptied(0),
1208
1208
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
1209
1209
    next_insert_id(0), insert_id_for_cur_row(0)
1210
1210
    {}
1211
1211
  virtual ~handler(void)
1212
1212
  {
1213
 
    DBUG_ASSERT(locked == FALSE);
1214
 
    /* TODO: DBUG_ASSERT(inited == NONE); */
 
1213
    assert(locked == false);
 
1214
    /* TODO: assert(inited == NONE); */
1215
1215
  }
1216
1216
  virtual handler *clone(MEM_ROOT *mem_root);
1217
1217
  /** This is called after create to allow us to set up cached variables */
1225
1225
  int ha_index_init(uint idx, bool sorted)
1226
1226
  {
1227
1227
    int result;
1228
 
    DBUG_ENTER("ha_index_init");
1229
 
    DBUG_ASSERT(inited==NONE);
 
1228
    assert(inited==NONE);
1230
1229
    if (!(result= index_init(idx, sorted)))
1231
1230
      inited=INDEX;
1232
1231
    end_range= NULL;
1233
 
    DBUG_RETURN(result);
 
1232
    return(result);
1234
1233
  }
1235
1234
  int ha_index_end()
1236
1235
  {
1237
 
    DBUG_ENTER("ha_index_end");
1238
 
    DBUG_ASSERT(inited==INDEX);
 
1236
    assert(inited==INDEX);
1239
1237
    inited=NONE;
1240
1238
    end_range= NULL;
1241
 
    DBUG_RETURN(index_end());
 
1239
    return(index_end());
1242
1240
  }
1243
1241
  int ha_rnd_init(bool scan)
1244
1242
  {
1245
1243
    int result;
1246
 
    DBUG_ENTER("ha_rnd_init");
1247
 
    DBUG_ASSERT(inited==NONE || (inited==RND && scan));
 
1244
    assert(inited==NONE || (inited==RND && scan));
1248
1245
    inited= (result= rnd_init(scan)) ? NONE: RND;
1249
 
    DBUG_RETURN(result);
 
1246
    return(result);
1250
1247
  }
1251
1248
  int ha_rnd_end()
1252
1249
  {
1253
 
    DBUG_ENTER("ha_rnd_end");
1254
 
    DBUG_ASSERT(inited==RND);
 
1250
    assert(inited==RND);
1255
1251
    inited=NONE;
1256
 
    DBUG_RETURN(rnd_end());
 
1252
    return(rnd_end());
1257
1253
  }
1258
1254
  int ha_reset();
1259
1255
  /* this is necessary in many places, e.g. in HANDLER command */
1361
1357
        ((flags & HA_CHECK_DUP_KEY) &&
1362
1358
         (error == HA_ERR_FOUND_DUPP_KEY ||
1363
1359
          error == HA_ERR_FOUND_DUPP_UNIQUE)))
1364
 
      return FALSE;
1365
 
    return TRUE;
 
1360
      return false;
 
1361
    return true;
1366
1362
  }
1367
1363
 
1368
1364
  /**
1386
1382
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
1387
1383
 
1388
1384
  virtual const char *index_type(uint key_number __attribute__((__unused__)))
1389
 
  { DBUG_ASSERT(0); return "";}
 
1385
  { assert(0); return "";}
1390
1386
 
1391
1387
 
1392
1388
  /**
1423
1419
  */
1424
1420
  virtual int exec_bulk_update(uint *dup_key_found __attribute__((__unused__)))
1425
1421
  {
1426
 
    DBUG_ASSERT(FALSE);
 
1422
    assert(false);
1427
1423
    return HA_ERR_WRONG_COMMAND;
1428
1424
  }
1429
1425
  /**
1439
1435
  */
1440
1436
  virtual int end_bulk_delete()
1441
1437
  {
1442
 
    DBUG_ASSERT(FALSE);
 
1438
    assert(false);
1443
1439
    return HA_ERR_WRONG_COMMAND;
1444
1440
  }
1445
1441
  /**
1527
1523
  virtual void position(const uchar *record)=0;
1528
1524
  virtual int info(uint)=0; // see my_base.h for full description
1529
1525
  virtual uint32 calculate_key_hash_value(Field **field_array __attribute__((__unused__)))
1530
 
  { DBUG_ASSERT(0); return 0; }
 
1526
  { assert(0); return 0; }
1531
1527
  virtual int extra(enum ha_extra_function operation __attribute__((__unused__)))
1532
1528
  { return 0; }
1533
1529
  virtual int extra_opt(enum ha_extra_function operation,
1564
1560
                                  uint64_t *nb_reserved_values);
1565
1561
  void set_next_insert_id(uint64_t id)
1566
1562
  {
1567
 
    DBUG_PRINT("info",("auto_increment: next value %lu", (uint32_t)id));
1568
1563
    next_insert_id= id;
1569
1564
  }
1570
1565
  void restore_auto_increment(uint64_t prev_insert_id)
1602
1597
 
1603
1598
    @param  index            Index to check if foreign key uses it
1604
1599
 
1605
 
    @retval   TRUE            Foreign key defined on table or index
1606
 
    @retval   FALSE           No foreign key defined
 
1600
    @retval   true            Foreign key defined on table or index
 
1601
    @retval   false           No foreign key defined
1607
1602
  */
1608
1603
  virtual bool is_fk_defined_on_table_or_index(uint index __attribute__((__unused__)))
1609
 
  { return FALSE; }
 
1604
  { return false; }
1610
1605
  virtual char* get_foreign_key_create_info(void)
1611
1606
  { return(NULL);}  /* gets foreign key create string from InnoDB */
1612
1607
  /** used in ALTER TABLE; 1 if changing storage engine is allowed */
1731
1726
 
1732
1727
    @note If engine_data supplied with this function is different from
1733
1728
      engine_data supplied with the callback function, and the callback returns
1734
 
      FALSE, a table invalidation on the current table will occur.
 
1729
      false, a table invalidation on the current table will occur.
1735
1730
 
1736
1731
    @return Upon success the engine_callback will point to the storage engine
1737
1732
      call back function, if any, and engine_data will point to any storage
1738
1733
      engine data used in the specific implementation.
1739
 
      @retval TRUE Success
1740
 
      @retval FALSE The specified table or current statement should not be
 
1734
      @retval true Success
 
1735
      @retval false The specified table or current statement should not be
1741
1736
        cached
1742
1737
  */
1743
1738
 
1749
1744
                               uint64_t *engine_data __attribute__((__unused__)))
1750
1745
  {
1751
1746
    *engine_callback= 0;
1752
 
    return TRUE;
 
1747
    return true;
1753
1748
  }
1754
1749
 
1755
1750
 
1756
1751
 /*
1757
 
   @retval TRUE   Primary key (if there is one) is clustered
 
1752
   @retval true   Primary key (if there is one) is clustered
1758
1753
                  key covering all fields
1759
 
   @retval FALSE  otherwise
 
1754
   @retval false  otherwise
1760
1755
 */
1761
 
 virtual bool primary_key_is_clustered() { return FALSE; }
 
1756
 virtual bool primary_key_is_clustered() { return false; }
1762
1757
 virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
1763
1758
 {
1764
1759
   return memcmp(ref1, ref2, ref_length);
1843
1838
                            HA_ALTER_FLAGS *alter_flags __attribute__((__unused__)),
1844
1839
                            uint table_changes)
1845
1840
 {
1846
 
   DBUG_ENTER("check_if_supported_alter");
1847
1841
   if (this->check_if_incompatible_data(create_info, table_changes)
1848
1842
       == COMPATIBLE_DATA_NO)
1849
 
     DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
 
1843
     return(HA_ALTER_NOT_SUPPORTED);
1850
1844
   else
1851
 
     DBUG_RETURN(HA_ALTER_SUPPORTED_WAIT_LOCK);
 
1845
     return(HA_ALTER_SUPPORTED_WAIT_LOCK);
1852
1846
 }
1853
1847
 /**
1854
1848
   Tell storage engine to prepare for the on-line alter table (pre-alter)
2087
2081
                              uchar *new_data __attribute__((__unused__)),
2088
2082
                              uint *dup_key_found __attribute__((__unused__)))
2089
2083
  {
2090
 
    DBUG_ASSERT(FALSE);
 
2084
    assert(false);
2091
2085
    return HA_ERR_WRONG_COMMAND;
2092
2086
  }
2093
2087
  /**
2113
2107
                      HA_CHECK_OPT* check_opt __attribute__((__unused__)))
2114
2108
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2115
2109
  virtual bool check_and_repair(THD *thd __attribute__((__unused__)))
2116
 
  { return TRUE; }
 
2110
  { return true; }
2117
2111
  virtual int disable_indexes(uint mode __attribute__((__unused__)))
2118
2112
  { return HA_ERR_WRONG_COMMAND; }
2119
2113
  virtual int enable_indexes(uint mode __attribute__((__unused__)))
2130
2124
                                   const char *old_name __attribute__((__unused__)),
2131
2125
                                   int action_flag __attribute__((__unused__)),
2132
2126
                                   HA_CREATE_INFO *info __attribute__((__unused__)))
2133
 
  { return FALSE; }
 
2127
  { return false; }
2134
2128
};
2135
2129
 
2136
2130
 
2168
2162
  uchar *rowids_buf_last;  /* When reading: end of used buffer space */
2169
2163
  uchar *rowids_buf_end;   /* End of the buffer */
2170
2164
 
2171
 
  bool dsmrr_eof; /* TRUE <=> We have reached EOF when reading index tuples */
 
2165
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
2172
2166
 
2173
 
  /* TRUE <=> need range association, buffer holds {rowid, range_id} pairs */
 
2167
  /* true <=> need range association, buffer holds {rowid, range_id} pairs */
2174
2168
  bool is_mrr_assoc;
2175
2169
 
2176
 
  bool use_default_impl; /* TRUE <=> shortcut all calls to default MRR impl */
 
2170
  bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
2177
2171
public:
2178
2172
  void init(handler *h_arg, TABLE *table_arg)
2179
2173
  {
2209
2203
extern uint32_t total_ha, total_ha_2pc;
2210
2204
 
2211
2205
       /* Wrapper functions */
2212
 
#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
2213
 
#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
 
2206
#define ha_commit(thd) (ha_commit_trans((thd), true))
 
2207
#define ha_rollback(thd) (ha_rollback_trans((thd), true))
2214
2208
 
2215
2209
/* lookups */
2216
2210
handlerton *ha_default_handlerton(THD *thd);
2235
2229
 
2236
2230
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag)
2237
2231
{
2238
 
  return db_type == NULL ? FALSE : test(db_type->flags & flag);
 
2232
  return db_type == NULL ? false : test(db_type->flags & flag);
2239
2233
}
2240
2234
 
2241
2235
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
2242
2236
{
2243
2237
  return (db_type && db_type->create) ?
2244
 
         (db_type->state == SHOW_OPTION_YES) : FALSE;
 
2238
         (db_type->state == SHOW_OPTION_YES) : false;
2245
2239
}
2246
2240
 
2247
2241
/* basic stuff */