~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Prafulla Tekawade
  • Date: 2010-07-18 03:36:32 UTC
  • mto: (1662.1.4 rollup)
  • mto: This revision was merged to the branch mainline in revision 1664.
  • Revision ID: prafulla_t@users.sourceforge.net-20100718033632-p7q6qtgliqbhe38p
Fix for Bug 592444

There were two problems:
o. In greedy_search optimizer method, best_extension_by_limited search
   maintains join embedding(nestedness) of tables added so far, so that 
   correct(valid)  join order is selected
   These are requirements from nested outer join executioner.
   The problem was, embedding_map was not correctly updated when a table 
   is added to optimal plan outside best_extension_by_limited search, 
   by greedy_search method. We need to update join->cur_embedding_map
   correctly here so that execution plan for other tables get
   generated.
   Invoked checked_interleaving_with_nj from greedy_search on the
   best_table selected. Fixed its prototype to take only one JoinTab
   This is same as mysql 5.1 source tree.
o. The other problem was, join->cur_embedding_map was not restored correctly
   when a table is added to the optimal plan to reflect the current embedding 
   map. 
   Taken good documented method restore_prev_nj_state which restores 
   cur_embedding_map from mysql 5.1 source tree and modified it for drizzled 
   code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "drizzled/sql_error.h"
29
29
#include "drizzled/decimal.h"
30
30
#include "drizzled/key_map.h"
 
31
#include "drizzled/sql_bitmap.h"
31
32
#include "drizzled/sql_list.h"
32
33
#include "drizzled/structs.h"
33
34
#include "drizzled/charset_info.h"
43
44
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
44
45
 
45
46
#ifdef DEBUG
46
 
#define ASSERT_COLUMN_MARKED_FOR_READ assert(!getTable() || (getTable()->read_set == NULL || isReadSet()))
47
 
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(!getTable() || (getTable()->write_set == NULL || isWriteSet()))
 
47
#define ASSERT_COLUMN_MARKED_FOR_READ assert(!table || (table->read_set == NULL || isReadSet()))
 
48
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(!table || (table->write_set == NULL || isWriteSet()))
48
49
#else
49
 
#define ASSERT_COLUMN_MARKED_FOR_READ assert(getTable())
50
 
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(getTable())
 
50
#define ASSERT_COLUMN_MARKED_FOR_READ
 
51
#define ASSERT_COLUMN_MARKED_FOR_WRITE
51
52
#endif
52
53
 
53
54
typedef struct st_typelib TYPELIB;
62
63
 
63
64
int field_conv(Field *to,Field *from);
64
65
 
 
66
inline uint32_t get_enum_pack_length(int elements)
 
67
{
 
68
  return elements < 256 ? 1 : 2;
 
69
}
 
70
 
65
71
/**
66
72
 * Class representing a Field in a Table
67
73
 *
80
86
  /* Prevent use of these */
81
87
  Field(const Field&);
82
88
  void operator=(Field &);
83
 
 
84
89
public:
85
90
  unsigned char *ptr; /**< Position to field in record. Stores raw field value */
86
91
  unsigned char *null_ptr; /**< Byte where null_bit is */
91
96
   * @note You can use table->in_use as replacement for current_session member
92
97
   * only inside of val_*() and store() members (e.g. you can't use it in cons)
93
98
   */
94
 
private:
95
99
  Table *table;
96
 
public:
97
100
  Table *getTable()
98
101
  {
99
102
    assert(table);
100
103
    return table;
101
104
  }
102
105
 
103
 
  Table *getTable() const
104
 
  {
105
 
    assert(table);
106
 
    return table;
107
 
  }
108
 
 
109
 
  void setTable(Table *table_arg)
110
 
  {
111
 
    table= table_arg;
112
 
  }
113
 
 
114
106
  Table *orig_table; /**< Pointer to the original Table. @TODO What is "the original table"? */
 
107
  const char **table_name; /**< Pointer to the name of the table. @TODO This is redundant with Table::table_name. */
115
108
  const char *field_name; /**< Name of the field */
116
109
  LEX_STRING comment; /**< A comment about the field */
117
110
 
141
134
  utype unireg_check;
142
135
  uint32_t field_length; /**< Length of this field in bytes */
143
136
  uint32_t flags;
144
 
private:
145
137
  uint16_t field_index; /**< Index of this Field in Table::fields array */
146
 
 
147
 
public:
148
 
 
149
 
  uint16_t position() const
150
 
  {
151
 
    return field_index;
152
 
  }
153
 
 
154
 
  void setPosition(uint32_t arg)
155
 
  {
156
 
    field_index= arg;
157
 
  }
158
 
 
159
138
  unsigned char null_bit; /**< Bit used to test null bit */
160
139
  /**
161
140
     If true, this field was created in create_tmp_field_from_item from a NULL
171
150
  static void *operator new(size_t size, memory::Root *mem_root);
172
151
  static void operator delete(void *, size_t)
173
152
  { }
174
 
  static void operator delete(void *, memory::Root *)
175
 
  { }
176
153
 
177
154
  Field(unsigned char *ptr_arg,
178
155
        uint32_t length_arg,
181
158
        utype unireg_check_arg,
182
159
        const char *field_name_arg);
183
160
  virtual ~Field() {}
184
 
 
185
 
  bool hasDefault() const
186
 
  {
187
 
    return not (flags & NO_DEFAULT_VALUE_FLAG);
188
 
  }
189
 
 
190
161
  /* Store functions returns 1 on overflow and -1 on fatal error */
191
162
  virtual int store(const char *to,
192
163
                    uint32_t length,
194
165
  virtual int store(double nr)=0;
195
166
  virtual int store(int64_t nr, bool unsigned_val)=0;
196
167
  virtual int store_decimal(const my_decimal *d)=0;
197
 
  int store_and_check(enum_check_fields check_level,
198
 
                      const char *to,
199
 
                      uint32_t length,
200
 
                      const CHARSET_INFO * const cs);
 
168
  int store(const char *to,
 
169
            uint32_t length,
 
170
            const CHARSET_INFO * const cs,
 
171
            enum_check_fields check_level);
201
172
  /**
202
173
    This is called when storing a date in a string.
203
174
 
205
176
      Needs to be changed if/when we want to support different time formats.
206
177
  */
207
178
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
208
 
  virtual double val_real()=0;
209
 
  virtual int64_t val_int()=0;
 
179
  virtual double val_real(void)=0;
 
180
  virtual int64_t val_int(void)=0;
210
181
  virtual my_decimal *val_decimal(my_decimal *);
211
 
  String *val_str_internal(String *str)
 
182
  inline String *val_str(String *str)
212
183
  {
213
184
    return val_str(str, str);
214
185
  }
322
293
  virtual uint32_t key_length() const;
323
294
  virtual enum_field_types type() const =0;
324
295
  virtual enum_field_types real_type() const;
325
 
  virtual int cmp_max(const unsigned char *a, const unsigned char *b, uint32_t max_len);
 
296
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
 
297
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
 
298
                      uint32_t max_len);
326
299
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
327
 
  int cmp_internal(const unsigned char *str) { return cmp(ptr,str); }
328
300
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
329
301
                         uint32_t max_length=UINT32_MAX);
330
302
  virtual int cmp_offset(uint32_t row_offset);
376
348
                               uint32_t new_null_bit);
377
349
  /** This is used to generate a field in Table from TableShare */
378
350
  Field *clone(memory::Root *mem_root, Table *new_table);
379
 
  void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
 
351
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
380
352
  {
381
353
    ptr= ptr_arg;
382
354
    null_ptr= null_ptr_arg;
383
355
    null_bit= null_bit_arg;
384
356
  }
385
 
  void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
 
357
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
386
358
  virtual void move_field_offset(ptrdiff_t ptr_diff)
387
359
  {
388
360
    ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
440
412
  {
441
413
    set_image(buff,length, &my_charset_bin);
442
414
  }
443
 
  int64_t val_int_offset(uint32_t row_offset)
 
415
  inline int64_t val_int_offset(uint32_t row_offset)
444
416
  {
445
417
    ptr+=row_offset;
446
418
    int64_t tmp=val_int();
448
420
    return tmp;
449
421
  }
450
422
 
451
 
  int64_t val_int_internal(const unsigned char *new_ptr)
 
423
  inline int64_t val_int(const unsigned char *new_ptr)
452
424
  {
453
425
    unsigned char *old_ptr= ptr;
454
426
    int64_t return_value;
457
429
    ptr= old_ptr;
458
430
    return return_value;
459
431
  }
460
 
 
461
 
  String *val_str_internal(String *str, const unsigned char *new_ptr)
 
432
  inline String *val_str(String *str, const unsigned char *new_ptr)
462
433
  {
463
434
    unsigned char *old_ptr= ptr;
464
435
    ptr= const_cast<unsigned char*>(new_ptr);
465
 
    val_str_internal(str);
 
436
    val_str(str);
466
437
    ptr= old_ptr;
467
438
    return str;
468
439
  }
571
542
    return max_length;
572
543
  }
573
544
 
574
 
  uint32_t offset(const unsigned char *record)
 
545
  inline uint32_t offset(const unsigned char *record)
575
546
  {
576
547
    return (uint32_t) (ptr - record);
577
548
  }
669
640
                            const uint32_t code,
670
641
                            double nr,
671
642
                            enum enum_drizzle_timestamp_type ts_type);
672
 
  bool check_overflow(int op_result)
 
643
  inline bool check_overflow(int op_result)
673
644
  {
674
645
    return (op_result == E_DEC_OVERFLOW);
675
646
  }
707
678
                                  bool unsigned_flag,
708
679
                                  int *err);
709
680
  /* The max. number of characters */
710
 
  uint32_t char_length() const
 
681
  inline uint32_t char_length() const
711
682
  {
712
683
    return field_length / charset()->mbmaxlen;
713
684
  }
714
685
 
715
 
  enum column_format_type column_format() const
 
686
  inline enum column_format_type column_format() const
716
687
  {
717
688
    return (enum column_format_type)
718
689
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
741
712
  void setWriteSet(bool arg= true);
742
713
};
743
714
 
744
 
std::ostream& operator<<(std::ostream& output, const Field &field);
745
 
 
746
715
} /* namespace drizzled */
747
716
 
748
717
/** @TODO Why is this in the middle of the file???*/