~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_select.h

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
19
16
 
20
17
/**
21
18
  @file
28
25
#pragma interface                       /* gcc class implementation */
29
26
#endif
30
27
 
31
 
/* PREV_BITS only used in sql_select.cc */
32
 
#define PREV_BITS(type,A)       ((type) (((type) 1 << (A)) -1))
33
 
 
34
 
#include <storage/myisam/myisam.h>
 
28
#include <myisam.h>
35
29
 
36
30
/* Values in optimize */
37
31
#define KEY_OPTIMIZE_EXISTS             1
38
32
#define KEY_OPTIMIZE_REF_OR_NULL        2
39
33
 
40
34
typedef struct keyuse_t {
41
 
  Table *table;
 
35
  TABLE *table;
42
36
  Item  *val;                           /**< or value if no field */
43
37
  table_map used_tables;
44
38
  uint  key, keypart;
45
 
  uint32_t optimize; // 0, or KEY_OPTIMIZE_*
 
39
  uint optimize; // 0, or KEY_OPTIMIZE_*
46
40
  key_part_map keypart_map;
47
41
  ha_rows      ref_table_rows;
48
42
  /**
55
49
            an Item_func_trig_cond. This means the equality (and validity of 
56
50
            this KEYUSE element) can be turned on and off. The on/off state 
57
51
            is indicted by the pointed value:
58
 
              *cond_guard == true <=> equality condition is on
59
 
              *cond_guard == false <=> equality condition is off
 
52
              *cond_guard == TRUE <=> equality condition is on
 
53
              *cond_guard == FALSE <=> equality condition is off
60
54
 
61
55
    NULL  - Otherwise (the source equality can't be turned off)
62
56
  */
65
59
     0..64    <=> This was created from semi-join IN-equality # sj_pred_no.
66
60
     MAX_UINT  Otherwise
67
61
  */
68
 
  uint32_t         sj_pred_no;
 
62
  uint         sj_pred_no;
69
63
} KEYUSE;
70
64
 
71
65
class store_key;
73
67
typedef struct st_table_ref
74
68
{
75
69
  bool          key_err;
76
 
  uint32_t      key_parts;                ///< num of ...
77
 
  uint32_t      key_length;               ///< length of key_buff
78
 
  int32_t       key;                      ///< key no
79
 
  unsigned char *key_buff;                ///< value to look for with key
80
 
  unsigned char *key_buff2;               ///< key_buff+key_length
 
70
  uint          key_parts;                ///< num of ...
 
71
  uint          key_length;               ///< length of key_buff
 
72
  int           key;                      ///< key no
 
73
  uchar         *key_buff;                ///< value to look for with key
 
74
  uchar         *key_buff2;               ///< key_buff+key_length
81
75
  store_key     **key_copy;               //
82
76
  Item          **items;                  ///< val()'s for each keypart
83
77
  /*  
99
93
  key_part_map  null_rejecting;
100
94
  table_map     depend_map;               ///< Table depends on these tables.
101
95
  /* null byte position in the key_buf. Used for REF_OR_NULL optimization */
102
 
  unsigned char *null_ref_key;
 
96
  uchar          *null_ref_key;
103
97
 
104
98
  /*
105
 
    true <=> disable the "cache" as doing lookup with the same key value may
 
99
    TRUE <=> disable the "cache" as doing lookup with the same key value may
106
100
    produce different results (because of Index Condition Pushdown)
107
101
  */
108
102
  bool          disable_cache;
119
113
    Where source data is located (i.e. this points to somewhere in 
120
114
    tableX->record[0])
121
115
  */
122
 
  unsigned char *str;
123
 
  uint32_t length; /* Length of data at *str, in bytes */
124
 
  uint32_t blob_length; /* Valid IFF blob_field != 0 */
 
116
  uchar *str;
 
117
  uint length; /* Length of data at *str, in bytes */
 
118
  uint blob_length; /* Valid IFF blob_field != 0 */
125
119
  Field_blob *blob_field;
126
 
  bool strip; /* true <=> Strip endspaces ?? */
 
120
  bool strip; /* TRUE <=> Strip endspaces ?? */
127
121
 
128
 
  Table *get_rowid; /* _ != NULL <=> */
 
122
  TABLE *get_rowid; /* _ != NULL <=> */
129
123
} CACHE_FIELD;
130
124
 
131
125
 
132
126
typedef struct st_join_cache 
133
127
{
134
 
  unsigned char *buff;
135
 
  unsigned char *pos;    /* Start of free space in the buffer */
136
 
  unsigned char *end;
137
 
  uint32_t records;  /* # of row cominations currently stored in the cache */
138
 
  uint32_t record_nr;
139
 
  uint32_t ptr_record; 
 
128
  uchar *buff;
 
129
  uchar *pos;    /* Start of free space in the buffer */
 
130
  uchar *end;
 
131
  uint records;  /* # of row cominations currently stored in the cache */
 
132
  uint record_nr;
 
133
  uint ptr_record; 
140
134
  /* 
141
135
    Number of fields (i.e. cache_field objects). Those correspond to table
142
136
    columns, and there are also special fields for
144
138
     - table's null-complementation byte
145
139
     - [new] table's rowid.
146
140
  */
147
 
  uint32_t fields; 
148
 
  uint32_t length; 
149
 
  uint32_t blobs;
 
141
  uint fields; 
 
142
  uint length; 
 
143
  uint blobs;
150
144
  CACHE_FIELD *field;
151
145
  CACHE_FIELD **blob_ptr;
152
146
  SQL_SELECT *select;
186
180
 
187
181
typedef struct st_join_table {
188
182
  st_join_table() {}                          /* Remove gcc warning */
189
 
  Table         *table;
 
183
  TABLE         *table;
190
184
  KEYUSE        *keyuse;                        /**< pointer to first used key */
191
185
  SQL_SELECT    *select;
192
186
  COND          *select_cond;
214
208
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
215
209
    column, or 0 if there is no info.
216
210
  */
217
 
  uint32_t          packed_info;
 
211
  uint          packed_info;
218
212
 
219
213
  Read_record_func read_first_record;
220
214
  Next_select_func next_select;
252
246
  uint          used_fields,used_fieldlength,used_blobs;
253
247
  enum join_type type;
254
248
  bool          cached_eq_ref_table,eq_ref_table,not_used_in_distinct;
255
 
  /* true <=> index-based access method must return records in order */
 
249
  /* TRUE <=> index-based access method must return records in order */
256
250
  bool          sorted;
257
251
  /* 
258
252
    If it's not 0 the number stored this field indicates that the index
270
264
    Embedding SJ-nest (may be not the direct parent), or NULL if none.
271
265
    This variable holds the result of table pullout.
272
266
  */
273
 
  TableList    *emb_sj_nest;
 
267
  TABLE_LIST    *emb_sj_nest;
274
268
 
275
269
  /* Variables for semi-join duplicate elimination */
276
270
  SJ_TMP_TABLE  *flush_weedout_table;
284
278
     NULL - Not an insideout scan.
285
279
  */
286
280
  struct st_join_table *insideout_match_tab;
287
 
  unsigned char *insideout_buf; // Buffer to save index tuple to be able to skip dups
 
281
  uchar *insideout_buf; // Buffer to save index tuple to be able to skip dups
288
282
 
289
283
  /* Used by InsideOut scan. Just set to true when have found a row. */
290
284
  bool found_match;
369
363
} ROLLUP;
370
364
 
371
365
 
 
366
/*
 
367
  Describes use of one temporary table to weed out join duplicates.
 
368
  The temporar
 
369
 
 
370
  Used to
 
371
    - create a temp table
 
372
    - when we reach the weed-out tab, walk through rowid-ed tabs and
 
373
      and copy rowids.
 
374
      For each table we need
 
375
       - rowid offset
 
376
       - null bit address.
 
377
*/
 
378
 
 
379
class SJ_TMP_TABLE : public Sql_alloc
 
380
{
 
381
public:
 
382
  /* Array of pointers to tables that should be "used" */
 
383
  class TAB
 
384
  {
 
385
  public:
 
386
    JOIN_TAB *join_tab;
 
387
    uint rowid_offset;
 
388
    ushort null_byte;
 
389
    uchar null_bit;
 
390
  };
 
391
  TAB *tabs;
 
392
  TAB *tabs_end;
 
393
 
 
394
  uint null_bits;
 
395
  uint null_bytes;
 
396
  uint rowid_len;
 
397
 
 
398
  TABLE *tmp_table;
 
399
 
 
400
  MI_COLUMNDEF *start_recinfo;
 
401
  MI_COLUMNDEF *recinfo;
 
402
 
 
403
  /* Pointer to next table (next->start_idx > this->end_idx) */
 
404
  SJ_TMP_TABLE *next; 
 
405
};
 
406
 
 
407
 
372
408
class JOIN :public Sql_alloc
373
409
{
374
410
  JOIN(const JOIN &rhs);                        /**< not implemented */
377
413
  JOIN_TAB *join_tab,**best_ref;
378
414
  JOIN_TAB **map2table;    ///< mapping between table indexes and JOIN_TABs
379
415
  JOIN_TAB *join_tab_save; ///< saved join_tab for subquery reexecution
380
 
  Table    **table,**all_tables;
 
416
  TABLE    **table,**all_tables;
381
417
  /**
382
418
    The table which has an index that allows to produce the requried ordering.
383
419
    A special value of 0x1 means that the ordering will be produced by
384
420
    passing 1st non-const table to filesort(). NULL means no such table exists.
385
421
  */
386
 
  Table    *sort_by_table;
 
422
  TABLE    *sort_by_table;
387
423
  uint     tables;        /**< Number of tables in the join */
388
 
  uint32_t     outer_tables;  /**< Number of tables that are not inside semijoin */
389
 
  uint32_t     const_tables;
 
424
  uint     outer_tables;  /**< Number of tables that are not inside semijoin */
 
425
  uint     const_tables;
390
426
  uint     send_group_parts;
391
427
  bool     sort_and_group,first_record,full_join,group, no_field_update;
392
428
  bool     do_send_rows;
393
429
  /**
394
 
    true when we want to resume nested loop iterations when
 
430
    TRUE when we want to resume nested loop iterations when
395
431
    fetching data from a cursor
396
432
  */
397
433
  bool     resume_nested_loop;
418
454
  double   best_read;
419
455
  List<Item> *fields;
420
456
  List<Cached_item> group_fields, group_fields_cache;
421
 
  Table    *tmp_table;
 
457
  TABLE    *tmp_table;
422
458
  /// used to store 2 possible tmp table of SELECT
423
 
  Table    *exec_tmp_table1, *exec_tmp_table2;
 
459
  TABLE    *exec_tmp_table1, *exec_tmp_table2;
424
460
  THD      *thd;
425
461
  Item_sum  **sum_funcs, ***sum_funcs_end;
426
462
  /** second copy of sumfuncs (for queries with 2 temporary tables */
428
464
  Item      *having;
429
465
  Item      *tmp_having; ///< To store having when processed temporary table
430
466
  Item      *having_history; ///< Store having for explain
431
 
  uint64_t  select_options;
 
467
  ulonglong  select_options;
432
468
  select_result *result;
433
469
  TMP_TABLE_PARAM tmp_table_param;
434
 
  DRIZZLE_LOCK *lock;
 
470
  MYSQL_LOCK *lock;
435
471
  /// unit structure (with global parameters) for this select
436
472
  SELECT_LEX_UNIT *unit;
437
473
  /// select that processed
438
474
  SELECT_LEX *select_lex;
439
475
  /** 
440
 
    true <=> optimizer must not mark any table as a constant table.
 
476
    TRUE <=> optimizer must not mark any table as a constant table.
441
477
    This is needed for subqueries in form "a IN (SELECT .. UNION SELECT ..):
442
478
    when we optimize the select that reads the results of the union from a
443
479
    temporary table, we must not mark the temp. table as constant because
452
488
  /**
453
489
    If we have the GROUP BY statement in the query,
454
490
    but the group_list was emptied by optimizer, this
455
 
    flag is true.
 
491
    flag is TRUE.
456
492
    It happens when fields in the GROUP BY are from
457
493
    constant table
458
494
  */
459
495
  bool group_optimized_away;
460
496
 
461
497
  /*
462
 
    simple_xxxxx is set if order_st/GROUP BY doesn't include any references
 
498
    simple_xxxxx is set if ORDER/GROUP BY doesn't include any references
463
499
    to other tables than the first non-constant table in the JOIN.
464
 
    It's also set if order_st/GROUP BY is empty.
 
500
    It's also set if ORDER/GROUP BY is empty.
465
501
  */
466
502
  bool simple_order, simple_group;
467
503
  /**
468
504
    Is set only in case if we have a GROUP BY clause
469
 
    and no order_st BY after constant elimination of 'order'.
 
505
    and no ORDER BY after constant elimination of 'order'.
470
506
  */
471
507
  bool no_order;
472
 
  /** Is set if we have a GROUP BY and we have order_st BY on a constant. */
 
508
  /** Is set if we have a GROUP BY and we have ORDER BY on a constant. */
473
509
  bool          skip_sort_order;
474
510
 
475
511
  bool need_tmp, hidden_group_fields;
483
519
  List<Item> &fields_list; ///< hold field list passed to mysql_select
484
520
  int error;
485
521
 
486
 
  order_st *order, *group_list, *proc_param; //hold parameters of mysql_select
 
522
  ORDER *order, *group_list, *proc_param; //hold parameters of mysql_select
487
523
  COND *conds;                            // ---"---
488
524
  Item *conds_history;                    // store WHERE for explain
489
 
  TableList *tables_list;           ///<hold 'tables' parameter of mysql_select
490
 
  List<TableList> *join_list;       ///< list of joined tables in reverse order
 
525
  TABLE_LIST *tables_list;           ///<hold 'tables' parameter of mysql_select
 
526
  List<TABLE_LIST> *join_list;       ///< list of joined tables in reverse order
491
527
  COND_EQUAL *cond_equal;
492
528
  SQL_SELECT *select;                ///<created in optimisation phase
493
529
  JOIN_TAB *return_tab;              ///<used only for outer joins
494
530
  Item **ref_pointer_array; ///<used pointer reference for this select
495
531
  // Copy of above to be used with different lists
496
532
  Item **items0, **items1, **items2, **items3, **current_ref_pointer_array;
497
 
  uint32_t ref_pointer_array_size; ///< size of above in bytes
 
533
  uint ref_pointer_array_size; ///< size of above in bytes
498
534
  const char *zero_result_cause; ///< not 0 if exec must return zero result
499
535
  
500
536
  bool union_part; ///< this subselect is part of union 
515
551
    excessive memory usage.
516
552
  */  
517
553
  SORT_FIELD *sortorder;                        // make_unireg_sortorder()
518
 
  Table **table_reexec;                         // make_simple_join()
 
554
  TABLE **table_reexec;                         // make_simple_join()
519
555
  JOIN_TAB *join_tab_reexec;                    // make_simple_join()
520
556
  /* end of allocation caching storage */
521
557
 
522
 
  JOIN(THD *thd_arg, List<Item> &fields_arg, uint64_t select_options_arg,
 
558
  JOIN(THD *thd_arg, List<Item> &fields_arg, ulonglong select_options_arg,
523
559
       select_result *result_arg)
524
560
    :fields_list(fields_arg), sj_subselects(thd_arg->mem_root, 4)
525
561
  {
526
562
    init(thd_arg, fields_arg, select_options_arg, result_arg);
527
563
  }
528
564
 
529
 
  void init(THD *thd_arg, List<Item> &fields_arg, uint64_t select_options_arg,
 
565
  void init(THD *thd_arg, List<Item> &fields_arg, ulonglong select_options_arg,
530
566
       select_result *result_arg)
531
567
  {
532
568
    join_tab= join_tab_save= 0;
537
573
    sort_and_group= 0;
538
574
    first_record= 0;
539
575
    do_send_rows= 1;
540
 
    resume_nested_loop= false;
 
576
    resume_nested_loop= FALSE;
541
577
    send_records= 0;
542
578
    found_records= 0;
543
579
    fetch_limit= HA_POS_ERROR;
574
610
 
575
611
    all_fields= fields_arg;
576
612
    fields_list= fields_arg;
577
 
    memset(&keyuse, 0, sizeof(keyuse));
 
613
    bzero((char*) &keyuse,sizeof(keyuse));
578
614
    tmp_table_param.init();
579
615
    tmp_table_param.end_write_records= HA_POS_ERROR;
580
616
    rollup.state= ROLLUP::STATE_NONE;
581
617
    sj_tmp_tables= NULL;
582
618
 
583
 
    no_const_tables= false;
 
619
    no_const_tables= FALSE;
584
620
  }
585
621
 
586
 
  int prepare(Item ***rref_pointer_array, TableList *tables, uint32_t wind_num,
587
 
              COND *conds, uint32_t og_num, order_st *order, order_st *group,
588
 
              Item *having, order_st *proc_param, SELECT_LEX *select,
 
622
  int prepare(Item ***rref_pointer_array, TABLE_LIST *tables, uint wind_num,
 
623
              COND *conds, uint og_num, ORDER *order, ORDER *group,
 
624
              Item *having, ORDER *proc_param, SELECT_LEX *select,
589
625
              SELECT_LEX_UNIT *unit);
590
626
  int optimize();
591
627
  int reinit();
596
632
  bool flatten_subqueries();
597
633
  bool setup_subquery_materialization();
598
634
  bool make_sum_func_list(List<Item> &all_fields, List<Item> &send_fields,
599
 
                          bool before_group_by, bool recompute= false);
 
635
                          bool before_group_by, bool recompute= FALSE);
600
636
 
601
637
  inline void set_items_ref_array(Item **ptr)
602
638
  {
603
 
    memcpy(ref_pointer_array, ptr, ref_pointer_array_size);
 
639
    memcpy((char*) ref_pointer_array, (char*) ptr, ref_pointer_array_size);
604
640
    current_ref_pointer_array= ptr;
605
641
  }
606
642
  inline void init_items_ref_array()
613
649
  bool rollup_init();
614
650
  bool rollup_make_fields(List<Item> &all_fields, List<Item> &fields,
615
651
                          Item_sum ***func);
616
 
  int rollup_send_data(uint32_t idx);
617
 
  int rollup_write_data(uint32_t idx, Table *table);
 
652
  int rollup_send_data(uint idx);
 
653
  int rollup_write_data(uint idx, TABLE *table);
618
654
  void remove_subq_pushed_predicates(Item **where);
619
655
  /**
620
656
    Release memory and, if possible, the open tables held by this execution
643
679
 
644
680
 
645
681
typedef struct st_select_check {
646
 
  uint32_t const_ref,reg_ref;
 
682
  uint const_ref,reg_ref;
647
683
} SELECT_CHECK;
648
684
 
649
685
extern const char *join_type_str[];
651
687
 
652
688
/* Extern functions in sql_select.cc */
653
689
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
654
 
Table *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
655
 
                        order_st *group, bool distinct, bool save_sum_fields,
656
 
                        uint64_t select_options, ha_rows rows_limit,
 
690
TABLE *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
 
691
                        ORDER *group, bool distinct, bool save_sum_fields,
 
692
                        ulonglong select_options, ha_rows rows_limit,
657
693
                        char* alias);
658
 
void free_tmp_table(THD *thd, Table *entry);
 
694
void free_tmp_table(THD *thd, TABLE *entry);
659
695
void count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param, 
660
696
                       List<Item> &fields, bool reset_with_sum_func);
661
697
bool setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
662
698
                       Item **ref_pointer_array,
663
699
                       List<Item> &new_list1, List<Item> &new_list2,
664
 
                       uint32_t elements, List<Item> &fields);
 
700
                       uint elements, List<Item> &fields);
665
701
void copy_fields(TMP_TABLE_PARAM *param);
666
702
void copy_funcs(Item **func_ptr);
 
703
bool create_myisam_from_heap(THD *thd, TABLE *table,
 
704
                             MI_COLUMNDEF *start_recinfo,
 
705
                             MI_COLUMNDEF **recinfo, 
 
706
                             int error, bool ignore_last_dupp_key_error);
 
707
uint find_shortest_key(TABLE *table, const key_map *usable_keys);
667
708
Field* create_tmp_field_from_field(THD *thd, Field* org_field,
668
 
                                   const char *name, Table *table,
669
 
                                   Item_field *item, uint32_t convert_blob_length);
 
709
                                   const char *name, TABLE *table,
 
710
                                   Item_field *item, uint convert_blob_length);
670
711
                                                                      
671
712
/* functions from opt_sum.cc */
672
713
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
673
 
int opt_sum_query(TableList *tables, List<Item> &all_fields,COND *conds);
 
714
int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds);
674
715
 
675
716
/* from sql_delete.cc, used by opt_range.cc */
676
717
extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b);
680
721
class store_key :public Sql_alloc
681
722
{
682
723
public:
683
 
  bool null_key; /* true <=> the value of the key has a null part */
 
724
  bool null_key; /* TRUE <=> the value of the key has a null part */
684
725
  enum store_key_result { STORE_KEY_OK, STORE_KEY_FATAL, STORE_KEY_CONV };
685
 
  store_key(THD *thd, Field *field_arg, unsigned char *ptr, unsigned char *null, uint32_t length)
 
726
  store_key(THD *thd, Field *field_arg, uchar *ptr, uchar *null, uint length)
686
727
    :null_key(0), null_ptr(null), err(0)
687
728
  {
688
 
    if (field_arg->type() == DRIZZLE_TYPE_BLOB)
 
729
    if (field_arg->type() == MYSQL_TYPE_BLOB)
689
730
    {
690
731
      /* 
691
732
        Key segments are always packed with a 2 byte length prefix.
726
767
 
727
768
 protected:
728
769
  Field *to_field;                              // Store data here
729
 
  unsigned char *null_ptr;
730
 
  unsigned char err;
 
770
  uchar *null_ptr;
 
771
  uchar err;
731
772
 
732
773
  virtual enum store_key_result copy_inner()=0;
733
774
};
738
779
  Copy_field copy_field;
739
780
  const char *field_name;
740
781
 public:
741
 
  store_key_field(THD *thd, Field *to_field_arg, unsigned char *ptr,
742
 
                  unsigned char *null_ptr_arg,
743
 
                  uint32_t length, Field *from_field, const char *name_arg)
 
782
  store_key_field(THD *thd, Field *to_field_arg, uchar *ptr,
 
783
                  uchar *null_ptr_arg,
 
784
                  uint length, Field *from_field, const char *name_arg)
744
785
    :store_key(thd, to_field_arg,ptr,
745
786
               null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
746
 
               : (unsigned char*) 0, length), field_name(name_arg)
 
787
               : (uchar*) 0, length), field_name(name_arg)
747
788
  {
748
789
    if (to_field)
749
790
    {
755
796
 protected: 
756
797
  enum store_key_result copy_inner()
757
798
  {
 
799
    TABLE *table= copy_field.to_field->table;
 
800
    my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
 
801
                                                     table->write_set);
758
802
    copy_field.do_copy(&copy_field);
 
803
    dbug_tmp_restore_column_map(table->write_set, old_map);
759
804
    null_key= to_field->is_null();
760
805
    return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
761
806
  }
767
812
 protected:
768
813
  Item *item;
769
814
public:
770
 
  store_key_item(THD *thd, Field *to_field_arg, unsigned char *ptr,
771
 
                 unsigned char *null_ptr_arg, uint32_t length, Item *item_arg)
 
815
  store_key_item(THD *thd, Field *to_field_arg, uchar *ptr,
 
816
                 uchar *null_ptr_arg, uint length, Item *item_arg)
772
817
    :store_key(thd, to_field_arg, ptr,
773
818
               null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
774
 
               &err : (unsigned char*) 0, length), item(item_arg)
 
819
               &err : (uchar*) 0, length), item(item_arg)
775
820
  {}
776
821
  const char *name() const { return "func"; }
777
822
 
778
823
 protected:  
779
824
  enum store_key_result copy_inner()
780
825
  {
 
826
    TABLE *table= to_field->table;
 
827
    my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
 
828
                                                     table->write_set);
781
829
    int res= item->save_in_field(to_field, 1);
 
830
    dbug_tmp_restore_column_map(table->write_set, old_map);
782
831
    null_key= to_field->is_null() || item->null_value;
783
832
    return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res); 
784
833
  }
789
838
{
790
839
  bool inited;
791
840
public:
792
 
  store_key_const_item(THD *thd, Field *to_field_arg, unsigned char *ptr,
793
 
                       unsigned char *null_ptr_arg, uint32_t length,
 
841
  store_key_const_item(THD *thd, Field *to_field_arg, uchar *ptr,
 
842
                       uchar *null_ptr_arg, uint length,
794
843
                       Item *item_arg)
795
844
    :store_key_item(thd, to_field_arg,ptr,
796
845
                    null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
797
 
                    &err : (unsigned char*) 0, length, item_arg), inited(0)
 
846
                    &err : (uchar*) 0, length, item_arg), inited(0)
798
847
  {
799
848
  }
800
849
  const char *name() const { return "const"; }
817
866
  }
818
867
};
819
868
 
820
 
bool cp_buffer_from_ref(THD *thd, TABLE_REF *ref);
 
869
bool cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref);
821
870
bool error_if_full_join(JOIN *join);
 
871
int report_error(TABLE *table, int error);
822
872
int safe_index_read(JOIN_TAB *tab);
823
873
COND *remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value);
824
874
int test_if_item_cache_changed(List<Cached_item> &list);