~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 22:08:52 UTC
  • mto: This revision was merged to the branch mainline in revision 77.
  • Revision ID: monty@inaugust.com-20080705220852-cqd9t6tfkhvlcf73
Removed HAVE_LONG_LONG, as this is now assumed.

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
24
21
  classes to use when handling where clause
25
22
*/
26
23
 
27
 
 
28
 
/* PREV_BITS only used in sql_select.cc */
29
 
#define PREV_BITS(type,A)       ((type) (((type) 1 << (A)) -1))
30
 
 
31
 
#include <storage/myisam/myisam.h>
 
24
#ifdef USE_PRAGMA_INTERFACE
 
25
#pragma interface                       /* gcc class implementation */
 
26
#endif
 
27
 
 
28
#include <myisam.h>
32
29
 
33
30
/* Values in optimize */
34
31
#define KEY_OPTIMIZE_EXISTS             1
35
32
#define KEY_OPTIMIZE_REF_OR_NULL        2
36
33
 
37
34
typedef struct keyuse_t {
38
 
  Table *table;
 
35
  TABLE *table;
39
36
  Item  *val;                           /**< or value if no field */
40
37
  table_map used_tables;
41
38
  uint  key, keypart;
42
 
  uint32_t optimize; // 0, or KEY_OPTIMIZE_*
 
39
  uint optimize; // 0, or KEY_OPTIMIZE_*
43
40
  key_part_map keypart_map;
44
41
  ha_rows      ref_table_rows;
45
42
  /**
52
49
            an Item_func_trig_cond. This means the equality (and validity of 
53
50
            this KEYUSE element) can be turned on and off. The on/off state 
54
51
            is indicted by the pointed value:
55
 
              *cond_guard == true <=> equality condition is on
56
 
              *cond_guard == false <=> equality condition is off
 
52
              *cond_guard == TRUE <=> equality condition is on
 
53
              *cond_guard == FALSE <=> equality condition is off
57
54
 
58
55
    NULL  - Otherwise (the source equality can't be turned off)
59
56
  */
62
59
     0..64    <=> This was created from semi-join IN-equality # sj_pred_no.
63
60
     MAX_UINT  Otherwise
64
61
  */
65
 
  uint32_t         sj_pred_no;
 
62
  uint         sj_pred_no;
66
63
} KEYUSE;
67
64
 
68
65
class store_key;
70
67
typedef struct st_table_ref
71
68
{
72
69
  bool          key_err;
73
 
  uint32_t      key_parts;                ///< num of ...
74
 
  uint32_t      key_length;               ///< length of key_buff
75
 
  int32_t       key;                      ///< key no
76
 
  unsigned char *key_buff;                ///< value to look for with key
77
 
  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
78
75
  store_key     **key_copy;               //
79
76
  Item          **items;                  ///< val()'s for each keypart
80
77
  /*  
96
93
  key_part_map  null_rejecting;
97
94
  table_map     depend_map;               ///< Table depends on these tables.
98
95
  /* null byte position in the key_buf. Used for REF_OR_NULL optimization */
99
 
  unsigned char *null_ref_key;
 
96
  uchar          *null_ref_key;
100
97
 
101
98
  /*
102
 
    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
103
100
    produce different results (because of Index Condition Pushdown)
104
101
  */
105
102
  bool          disable_cache;
116
113
    Where source data is located (i.e. this points to somewhere in 
117
114
    tableX->record[0])
118
115
  */
119
 
  unsigned char *str;
120
 
  uint32_t length; /* Length of data at *str, in bytes */
121
 
  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 */
122
119
  Field_blob *blob_field;
123
 
  bool strip; /* true <=> Strip endspaces ?? */
 
120
  bool strip; /* TRUE <=> Strip endspaces ?? */
124
121
 
125
 
  Table *get_rowid; /* _ != NULL <=> */
 
122
  TABLE *get_rowid; /* _ != NULL <=> */
126
123
} CACHE_FIELD;
127
124
 
128
125
 
129
126
typedef struct st_join_cache 
130
127
{
131
 
  unsigned char *buff;
132
 
  unsigned char *pos;    /* Start of free space in the buffer */
133
 
  unsigned char *end;
134
 
  uint32_t records;  /* # of row cominations currently stored in the cache */
135
 
  uint32_t record_nr;
136
 
  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; 
137
134
  /* 
138
135
    Number of fields (i.e. cache_field objects). Those correspond to table
139
136
    columns, and there are also special fields for
141
138
     - table's null-complementation byte
142
139
     - [new] table's rowid.
143
140
  */
144
 
  uint32_t fields; 
145
 
  uint32_t length; 
146
 
  uint32_t blobs;
 
141
  uint fields; 
 
142
  uint length; 
 
143
  uint blobs;
147
144
  CACHE_FIELD *field;
148
145
  CACHE_FIELD **blob_ptr;
149
146
  SQL_SELECT *select;
183
180
 
184
181
typedef struct st_join_table {
185
182
  st_join_table() {}                          /* Remove gcc warning */
186
 
  Table         *table;
 
183
  TABLE         *table;
187
184
  KEYUSE        *keyuse;                        /**< pointer to first used key */
188
185
  SQL_SELECT    *select;
189
186
  COND          *select_cond;
211
208
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
212
209
    column, or 0 if there is no info.
213
210
  */
214
 
  uint32_t          packed_info;
 
211
  uint          packed_info;
215
212
 
216
213
  Read_record_func read_first_record;
217
214
  Next_select_func next_select;
249
246
  uint          used_fields,used_fieldlength,used_blobs;
250
247
  enum join_type type;
251
248
  bool          cached_eq_ref_table,eq_ref_table,not_used_in_distinct;
252
 
  /* true <=> index-based access method must return records in order */
 
249
  /* TRUE <=> index-based access method must return records in order */
253
250
  bool          sorted;
254
251
  /* 
255
252
    If it's not 0 the number stored this field indicates that the index
267
264
    Embedding SJ-nest (may be not the direct parent), or NULL if none.
268
265
    This variable holds the result of table pullout.
269
266
  */
270
 
  TableList    *emb_sj_nest;
 
267
  TABLE_LIST    *emb_sj_nest;
271
268
 
272
269
  /* Variables for semi-join duplicate elimination */
273
270
  SJ_TMP_TABLE  *flush_weedout_table;
281
278
     NULL - Not an insideout scan.
282
279
  */
283
280
  struct st_join_table *insideout_match_tab;
284
 
  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
285
282
 
286
283
  /* Used by InsideOut scan. Just set to true when have found a row. */
287
284
  bool found_match;
366
363
} ROLLUP;
367
364
 
368
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
 
369
408
class JOIN :public Sql_alloc
370
409
{
371
410
  JOIN(const JOIN &rhs);                        /**< not implemented */
374
413
  JOIN_TAB *join_tab,**best_ref;
375
414
  JOIN_TAB **map2table;    ///< mapping between table indexes and JOIN_TABs
376
415
  JOIN_TAB *join_tab_save; ///< saved join_tab for subquery reexecution
377
 
  Table    **table,**all_tables;
 
416
  TABLE    **table,**all_tables;
378
417
  /**
379
418
    The table which has an index that allows to produce the requried ordering.
380
419
    A special value of 0x1 means that the ordering will be produced by
381
420
    passing 1st non-const table to filesort(). NULL means no such table exists.
382
421
  */
383
 
  Table    *sort_by_table;
 
422
  TABLE    *sort_by_table;
384
423
  uint     tables;        /**< Number of tables in the join */
385
 
  uint32_t     outer_tables;  /**< Number of tables that are not inside semijoin */
386
 
  uint32_t     const_tables;
 
424
  uint     outer_tables;  /**< Number of tables that are not inside semijoin */
 
425
  uint     const_tables;
387
426
  uint     send_group_parts;
388
427
  bool     sort_and_group,first_record,full_join,group, no_field_update;
389
428
  bool     do_send_rows;
390
429
  /**
391
 
    true when we want to resume nested loop iterations when
 
430
    TRUE when we want to resume nested loop iterations when
392
431
    fetching data from a cursor
393
432
  */
394
433
  bool     resume_nested_loop;
415
454
  double   best_read;
416
455
  List<Item> *fields;
417
456
  List<Cached_item> group_fields, group_fields_cache;
418
 
  Table    *tmp_table;
 
457
  TABLE    *tmp_table;
419
458
  /// used to store 2 possible tmp table of SELECT
420
 
  Table    *exec_tmp_table1, *exec_tmp_table2;
 
459
  TABLE    *exec_tmp_table1, *exec_tmp_table2;
421
460
  THD      *thd;
422
461
  Item_sum  **sum_funcs, ***sum_funcs_end;
423
462
  /** second copy of sumfuncs (for queries with 2 temporary tables */
425
464
  Item      *having;
426
465
  Item      *tmp_having; ///< To store having when processed temporary table
427
466
  Item      *having_history; ///< Store having for explain
428
 
  uint64_t  select_options;
 
467
  ulonglong  select_options;
429
468
  select_result *result;
430
469
  TMP_TABLE_PARAM tmp_table_param;
431
 
  DRIZZLE_LOCK *lock;
 
470
  MYSQL_LOCK *lock;
432
471
  /// unit structure (with global parameters) for this select
433
472
  SELECT_LEX_UNIT *unit;
434
473
  /// select that processed
435
474
  SELECT_LEX *select_lex;
436
475
  /** 
437
 
    true <=> optimizer must not mark any table as a constant table.
 
476
    TRUE <=> optimizer must not mark any table as a constant table.
438
477
    This is needed for subqueries in form "a IN (SELECT .. UNION SELECT ..):
439
478
    when we optimize the select that reads the results of the union from a
440
479
    temporary table, we must not mark the temp. table as constant because
449
488
  /**
450
489
    If we have the GROUP BY statement in the query,
451
490
    but the group_list was emptied by optimizer, this
452
 
    flag is true.
 
491
    flag is TRUE.
453
492
    It happens when fields in the GROUP BY are from
454
493
    constant table
455
494
  */
456
495
  bool group_optimized_away;
457
496
 
458
497
  /*
459
 
    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
460
499
    to other tables than the first non-constant table in the JOIN.
461
 
    It's also set if order_st/GROUP BY is empty.
 
500
    It's also set if ORDER/GROUP BY is empty.
462
501
  */
463
502
  bool simple_order, simple_group;
464
503
  /**
465
504
    Is set only in case if we have a GROUP BY clause
466
 
    and no order_st BY after constant elimination of 'order'.
 
505
    and no ORDER BY after constant elimination of 'order'.
467
506
  */
468
507
  bool no_order;
469
 
  /** 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. */
470
509
  bool          skip_sort_order;
471
510
 
472
511
  bool need_tmp, hidden_group_fields;
480
519
  List<Item> &fields_list; ///< hold field list passed to mysql_select
481
520
  int error;
482
521
 
483
 
  order_st *order, *group_list, *proc_param; //hold parameters of mysql_select
 
522
  ORDER *order, *group_list, *proc_param; //hold parameters of mysql_select
484
523
  COND *conds;                            // ---"---
485
524
  Item *conds_history;                    // store WHERE for explain
486
 
  TableList *tables_list;           ///<hold 'tables' parameter of mysql_select
487
 
  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
488
527
  COND_EQUAL *cond_equal;
489
528
  SQL_SELECT *select;                ///<created in optimisation phase
490
529
  JOIN_TAB *return_tab;              ///<used only for outer joins
491
530
  Item **ref_pointer_array; ///<used pointer reference for this select
492
531
  // Copy of above to be used with different lists
493
532
  Item **items0, **items1, **items2, **items3, **current_ref_pointer_array;
494
 
  uint32_t ref_pointer_array_size; ///< size of above in bytes
 
533
  uint ref_pointer_array_size; ///< size of above in bytes
495
534
  const char *zero_result_cause; ///< not 0 if exec must return zero result
496
535
  
497
536
  bool union_part; ///< this subselect is part of union 
512
551
    excessive memory usage.
513
552
  */  
514
553
  SORT_FIELD *sortorder;                        // make_unireg_sortorder()
515
 
  Table **table_reexec;                         // make_simple_join()
 
554
  TABLE **table_reexec;                         // make_simple_join()
516
555
  JOIN_TAB *join_tab_reexec;                    // make_simple_join()
517
556
  /* end of allocation caching storage */
518
557
 
519
 
  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,
520
559
       select_result *result_arg)
521
560
    :fields_list(fields_arg), sj_subselects(thd_arg->mem_root, 4)
522
561
  {
523
562
    init(thd_arg, fields_arg, select_options_arg, result_arg);
524
563
  }
525
564
 
526
 
  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,
527
566
       select_result *result_arg)
528
567
  {
529
568
    join_tab= join_tab_save= 0;
534
573
    sort_and_group= 0;
535
574
    first_record= 0;
536
575
    do_send_rows= 1;
537
 
    resume_nested_loop= false;
 
576
    resume_nested_loop= FALSE;
538
577
    send_records= 0;
539
578
    found_records= 0;
540
579
    fetch_limit= HA_POS_ERROR;
571
610
 
572
611
    all_fields= fields_arg;
573
612
    fields_list= fields_arg;
574
 
    memset(&keyuse, 0, sizeof(keyuse));
 
613
    bzero((char*) &keyuse,sizeof(keyuse));
575
614
    tmp_table_param.init();
576
615
    tmp_table_param.end_write_records= HA_POS_ERROR;
577
616
    rollup.state= ROLLUP::STATE_NONE;
578
617
    sj_tmp_tables= NULL;
579
618
 
580
 
    no_const_tables= false;
 
619
    no_const_tables= FALSE;
581
620
  }
582
621
 
583
 
  int prepare(Item ***rref_pointer_array, TableList *tables, uint32_t wind_num,
584
 
              COND *conds, uint32_t og_num, order_st *order, order_st *group,
585
 
              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,
586
625
              SELECT_LEX_UNIT *unit);
587
626
  int optimize();
588
627
  int reinit();
593
632
  bool flatten_subqueries();
594
633
  bool setup_subquery_materialization();
595
634
  bool make_sum_func_list(List<Item> &all_fields, List<Item> &send_fields,
596
 
                          bool before_group_by, bool recompute= false);
 
635
                          bool before_group_by, bool recompute= FALSE);
597
636
 
598
637
  inline void set_items_ref_array(Item **ptr)
599
638
  {
600
 
    memcpy(ref_pointer_array, ptr, ref_pointer_array_size);
 
639
    memcpy((char*) ref_pointer_array, (char*) ptr, ref_pointer_array_size);
601
640
    current_ref_pointer_array= ptr;
602
641
  }
603
642
  inline void init_items_ref_array()
610
649
  bool rollup_init();
611
650
  bool rollup_make_fields(List<Item> &all_fields, List<Item> &fields,
612
651
                          Item_sum ***func);
613
 
  int rollup_send_data(uint32_t idx);
614
 
  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);
615
654
  void remove_subq_pushed_predicates(Item **where);
616
655
  /**
617
656
    Release memory and, if possible, the open tables held by this execution
640
679
 
641
680
 
642
681
typedef struct st_select_check {
643
 
  uint32_t const_ref,reg_ref;
 
682
  uint const_ref,reg_ref;
644
683
} SELECT_CHECK;
645
684
 
646
685
extern const char *join_type_str[];
648
687
 
649
688
/* Extern functions in sql_select.cc */
650
689
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
651
 
Table *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
652
 
                        order_st *group, bool distinct, bool save_sum_fields,
653
 
                        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,
654
693
                        char* alias);
655
 
void free_tmp_table(THD *thd, Table *entry);
 
694
void free_tmp_table(THD *thd, TABLE *entry);
656
695
void count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param, 
657
696
                       List<Item> &fields, bool reset_with_sum_func);
658
697
bool setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
659
698
                       Item **ref_pointer_array,
660
699
                       List<Item> &new_list1, List<Item> &new_list2,
661
 
                       uint32_t elements, List<Item> &fields);
 
700
                       uint elements, List<Item> &fields);
662
701
void copy_fields(TMP_TABLE_PARAM *param);
663
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);
664
708
Field* create_tmp_field_from_field(THD *thd, Field* org_field,
665
 
                                   const char *name, Table *table,
666
 
                                   Item_field *item, uint32_t convert_blob_length);
 
709
                                   const char *name, TABLE *table,
 
710
                                   Item_field *item, uint convert_blob_length);
667
711
                                                                      
668
712
/* functions from opt_sum.cc */
669
713
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
670
 
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);
671
715
 
672
716
/* from sql_delete.cc, used by opt_range.cc */
673
717
extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b);
677
721
class store_key :public Sql_alloc
678
722
{
679
723
public:
680
 
  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 */
681
725
  enum store_key_result { STORE_KEY_OK, STORE_KEY_FATAL, STORE_KEY_CONV };
682
 
  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)
683
727
    :null_key(0), null_ptr(null), err(0)
684
728
  {
685
 
    if (field_arg->type() == DRIZZLE_TYPE_BLOB)
 
729
    if (field_arg->type() == MYSQL_TYPE_BLOB)
686
730
    {
687
731
      /* 
688
732
        Key segments are always packed with a 2 byte length prefix.
723
767
 
724
768
 protected:
725
769
  Field *to_field;                              // Store data here
726
 
  unsigned char *null_ptr;
727
 
  unsigned char err;
 
770
  uchar *null_ptr;
 
771
  uchar err;
728
772
 
729
773
  virtual enum store_key_result copy_inner()=0;
730
774
};
735
779
  Copy_field copy_field;
736
780
  const char *field_name;
737
781
 public:
738
 
  store_key_field(THD *thd, Field *to_field_arg, unsigned char *ptr,
739
 
                  unsigned char *null_ptr_arg,
740
 
                  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)
741
785
    :store_key(thd, to_field_arg,ptr,
742
786
               null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
743
 
               : (unsigned char*) 0, length), field_name(name_arg)
 
787
               : (uchar*) 0, length), field_name(name_arg)
744
788
  {
745
789
    if (to_field)
746
790
    {
752
796
 protected: 
753
797
  enum store_key_result copy_inner()
754
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);
755
802
    copy_field.do_copy(&copy_field);
 
803
    dbug_tmp_restore_column_map(table->write_set, old_map);
756
804
    null_key= to_field->is_null();
757
805
    return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
758
806
  }
764
812
 protected:
765
813
  Item *item;
766
814
public:
767
 
  store_key_item(THD *thd, Field *to_field_arg, unsigned char *ptr,
768
 
                 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)
769
817
    :store_key(thd, to_field_arg, ptr,
770
818
               null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
771
 
               &err : (unsigned char*) 0, length), item(item_arg)
 
819
               &err : (uchar*) 0, length), item(item_arg)
772
820
  {}
773
821
  const char *name() const { return "func"; }
774
822
 
775
823
 protected:  
776
824
  enum store_key_result copy_inner()
777
825
  {
 
826
    TABLE *table= to_field->table;
 
827
    my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
 
828
                                                     table->write_set);
778
829
    int res= item->save_in_field(to_field, 1);
 
830
    dbug_tmp_restore_column_map(table->write_set, old_map);
779
831
    null_key= to_field->is_null() || item->null_value;
780
832
    return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res); 
781
833
  }
786
838
{
787
839
  bool inited;
788
840
public:
789
 
  store_key_const_item(THD *thd, Field *to_field_arg, unsigned char *ptr,
790
 
                       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,
791
843
                       Item *item_arg)
792
844
    :store_key_item(thd, to_field_arg,ptr,
793
845
                    null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
794
 
                    &err : (unsigned char*) 0, length, item_arg), inited(0)
 
846
                    &err : (uchar*) 0, length, item_arg), inited(0)
795
847
  {
796
848
  }
797
849
  const char *name() const { return "const"; }
814
866
  }
815
867
};
816
868
 
817
 
bool cp_buffer_from_ref(THD *thd, TABLE_REF *ref);
 
869
bool cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref);
818
870
bool error_if_full_join(JOIN *join);
 
871
int report_error(TABLE *table, int error);
819
872
int safe_index_read(JOIN_TAB *tab);
820
873
COND *remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value);
821
874
int test_if_item_cache_changed(List<Cached_item> &list);