~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.h

Merged from jay.

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
 
 
24
#ifdef USE_PRAGMA_INTERFACE
 
25
#pragma interface                       /* gcc class implementation */
 
26
#endif
27
27
 
28
28
/* PREV_BITS only used in sql_select.cc */
29
29
#define PREV_BITS(type,A)       ((type) (((type) 1 << (A)) -1))
30
30
 
31
31
#include <storage/myisam/myisam.h>
32
 
#include <drizzled/sql_array.h>
33
32
 
34
33
/* Values in optimize */
35
34
#define KEY_OPTIMIZE_EXISTS             1
36
35
#define KEY_OPTIMIZE_REF_OR_NULL        2
37
36
 
38
37
typedef struct keyuse_t {
39
 
  Table *table;
 
38
  TABLE *table;
40
39
  Item  *val;                           /**< or value if no field */
41
40
  table_map used_tables;
42
41
  uint  key, keypart;
43
 
  uint32_t optimize; // 0, or KEY_OPTIMIZE_*
 
42
  uint optimize; // 0, or KEY_OPTIMIZE_*
44
43
  key_part_map keypart_map;
45
44
  ha_rows      ref_table_rows;
46
45
  /**
63
62
     0..64    <=> This was created from semi-join IN-equality # sj_pred_no.
64
63
     MAX_UINT  Otherwise
65
64
  */
66
 
  uint32_t         sj_pred_no;
 
65
  uint         sj_pred_no;
67
66
} KEYUSE;
68
67
 
69
68
class store_key;
71
70
typedef struct st_table_ref
72
71
{
73
72
  bool          key_err;
74
 
  uint32_t      key_parts;                ///< num of ...
75
 
  uint32_t      key_length;               ///< length of key_buff
76
 
  int32_t       key;                      ///< key no
77
 
  unsigned char *key_buff;                ///< value to look for with key
78
 
  unsigned char *key_buff2;               ///< key_buff+key_length
 
73
  uint          key_parts;                ///< num of ...
 
74
  uint          key_length;               ///< length of key_buff
 
75
  int           key;                      ///< key no
 
76
  uchar         *key_buff;                ///< value to look for with key
 
77
  uchar         *key_buff2;               ///< key_buff+key_length
79
78
  store_key     **key_copy;               //
80
79
  Item          **items;                  ///< val()'s for each keypart
81
80
  /*  
97
96
  key_part_map  null_rejecting;
98
97
  table_map     depend_map;               ///< Table depends on these tables.
99
98
  /* null byte position in the key_buf. Used for REF_OR_NULL optimization */
100
 
  unsigned char *null_ref_key;
 
99
  uchar          *null_ref_key;
101
100
 
102
101
  /*
103
102
    true <=> disable the "cache" as doing lookup with the same key value may
117
116
    Where source data is located (i.e. this points to somewhere in 
118
117
    tableX->record[0])
119
118
  */
120
 
  unsigned char *str;
121
 
  uint32_t length; /* Length of data at *str, in bytes */
122
 
  uint32_t blob_length; /* Valid IFF blob_field != 0 */
 
119
  uchar *str;
 
120
  uint length; /* Length of data at *str, in bytes */
 
121
  uint blob_length; /* Valid IFF blob_field != 0 */
123
122
  Field_blob *blob_field;
124
123
  bool strip; /* true <=> Strip endspaces ?? */
125
124
 
126
 
  Table *get_rowid; /* _ != NULL <=> */
 
125
  TABLE *get_rowid; /* _ != NULL <=> */
127
126
} CACHE_FIELD;
128
127
 
129
128
 
130
129
typedef struct st_join_cache 
131
130
{
132
 
  unsigned char *buff;
133
 
  unsigned char *pos;    /* Start of free space in the buffer */
134
 
  unsigned char *end;
135
 
  uint32_t records;  /* # of row cominations currently stored in the cache */
136
 
  uint32_t record_nr;
137
 
  uint32_t ptr_record; 
 
131
  uchar *buff;
 
132
  uchar *pos;    /* Start of free space in the buffer */
 
133
  uchar *end;
 
134
  uint records;  /* # of row cominations currently stored in the cache */
 
135
  uint record_nr;
 
136
  uint ptr_record; 
138
137
  /* 
139
138
    Number of fields (i.e. cache_field objects). Those correspond to table
140
139
    columns, and there are also special fields for
142
141
     - table's null-complementation byte
143
142
     - [new] table's rowid.
144
143
  */
145
 
  uint32_t fields; 
146
 
  uint32_t length; 
147
 
  uint32_t blobs;
 
144
  uint fields; 
 
145
  uint length; 
 
146
  uint blobs;
148
147
  CACHE_FIELD *field;
149
148
  CACHE_FIELD **blob_ptr;
150
149
  SQL_SELECT *select;
184
183
 
185
184
typedef struct st_join_table {
186
185
  st_join_table() {}                          /* Remove gcc warning */
187
 
  Table         *table;
 
186
  TABLE         *table;
188
187
  KEYUSE        *keyuse;                        /**< pointer to first used key */
189
188
  SQL_SELECT    *select;
190
189
  COND          *select_cond;
212
211
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
213
212
    column, or 0 if there is no info.
214
213
  */
215
 
  uint32_t          packed_info;
 
214
  uint          packed_info;
216
215
 
217
216
  Read_record_func read_first_record;
218
217
  Next_select_func next_select;
268
267
    Embedding SJ-nest (may be not the direct parent), or NULL if none.
269
268
    This variable holds the result of table pullout.
270
269
  */
271
 
  TableList    *emb_sj_nest;
 
270
  TABLE_LIST    *emb_sj_nest;
272
271
 
273
272
  /* Variables for semi-join duplicate elimination */
274
273
  SJ_TMP_TABLE  *flush_weedout_table;
282
281
     NULL - Not an insideout scan.
283
282
  */
284
283
  struct st_join_table *insideout_match_tab;
285
 
  unsigned char *insideout_buf; // Buffer to save index tuple to be able to skip dups
 
284
  uchar *insideout_buf; // Buffer to save index tuple to be able to skip dups
286
285
 
287
286
  /* Used by InsideOut scan. Just set to true when have found a row. */
288
287
  bool found_match;
367
366
} ROLLUP;
368
367
 
369
368
 
 
369
/*
 
370
  Describes use of one temporary table to weed out join duplicates.
 
371
  The temporar
 
372
 
 
373
  Used to
 
374
    - create a temp table
 
375
    - when we reach the weed-out tab, walk through rowid-ed tabs and
 
376
      and copy rowids.
 
377
      For each table we need
 
378
       - rowid offset
 
379
       - null bit address.
 
380
*/
 
381
 
 
382
class SJ_TMP_TABLE : public Sql_alloc
 
383
{
 
384
public:
 
385
  /* Array of pointers to tables that should be "used" */
 
386
  class TAB
 
387
  {
 
388
  public:
 
389
    JOIN_TAB *join_tab;
 
390
    uint rowid_offset;
 
391
    ushort null_byte;
 
392
    uchar null_bit;
 
393
  };
 
394
  TAB *tabs;
 
395
  TAB *tabs_end;
 
396
 
 
397
  uint null_bits;
 
398
  uint null_bytes;
 
399
  uint rowid_len;
 
400
 
 
401
  TABLE *tmp_table;
 
402
 
 
403
  MI_COLUMNDEF *start_recinfo;
 
404
  MI_COLUMNDEF *recinfo;
 
405
 
 
406
  /* Pointer to next table (next->start_idx > this->end_idx) */
 
407
  SJ_TMP_TABLE *next; 
 
408
};
 
409
 
 
410
 
370
411
class JOIN :public Sql_alloc
371
412
{
372
413
  JOIN(const JOIN &rhs);                        /**< not implemented */
375
416
  JOIN_TAB *join_tab,**best_ref;
376
417
  JOIN_TAB **map2table;    ///< mapping between table indexes and JOIN_TABs
377
418
  JOIN_TAB *join_tab_save; ///< saved join_tab for subquery reexecution
378
 
  Table    **table,**all_tables;
 
419
  TABLE    **table,**all_tables;
379
420
  /**
380
421
    The table which has an index that allows to produce the requried ordering.
381
422
    A special value of 0x1 means that the ordering will be produced by
382
423
    passing 1st non-const table to filesort(). NULL means no such table exists.
383
424
  */
384
 
  Table    *sort_by_table;
 
425
  TABLE    *sort_by_table;
385
426
  uint     tables;        /**< Number of tables in the join */
386
 
  uint32_t     outer_tables;  /**< Number of tables that are not inside semijoin */
387
 
  uint32_t     const_tables;
 
427
  uint     outer_tables;  /**< Number of tables that are not inside semijoin */
 
428
  uint     const_tables;
388
429
  uint     send_group_parts;
389
430
  bool     sort_and_group,first_record,full_join,group, no_field_update;
390
431
  bool     do_send_rows;
416
457
  double   best_read;
417
458
  List<Item> *fields;
418
459
  List<Cached_item> group_fields, group_fields_cache;
419
 
  Table    *tmp_table;
 
460
  TABLE    *tmp_table;
420
461
  /// used to store 2 possible tmp table of SELECT
421
 
  Table    *exec_tmp_table1, *exec_tmp_table2;
422
 
  Session          *session;
 
462
  TABLE    *exec_tmp_table1, *exec_tmp_table2;
 
463
  THD      *thd;
423
464
  Item_sum  **sum_funcs, ***sum_funcs_end;
424
465
  /** second copy of sumfuncs (for queries with 2 temporary tables */
425
466
  Item_sum  **sum_funcs2, ***sum_funcs_end2;
429
470
  uint64_t  select_options;
430
471
  select_result *result;
431
472
  TMP_TABLE_PARAM tmp_table_param;
432
 
  DRIZZLE_LOCK *lock;
 
473
  MYSQL_LOCK *lock;
433
474
  /// unit structure (with global parameters) for this select
434
475
  SELECT_LEX_UNIT *unit;
435
476
  /// select that processed
457
498
  bool group_optimized_away;
458
499
 
459
500
  /*
460
 
    simple_xxxxx is set if order_st/GROUP BY doesn't include any references
 
501
    simple_xxxxx is set if ORDER/GROUP BY doesn't include any references
461
502
    to other tables than the first non-constant table in the JOIN.
462
 
    It's also set if order_st/GROUP BY is empty.
 
503
    It's also set if ORDER/GROUP BY is empty.
463
504
  */
464
505
  bool simple_order, simple_group;
465
506
  /**
466
507
    Is set only in case if we have a GROUP BY clause
467
 
    and no order_st BY after constant elimination of 'order'.
 
508
    and no ORDER BY after constant elimination of 'order'.
468
509
  */
469
510
  bool no_order;
470
 
  /** Is set if we have a GROUP BY and we have order_st BY on a constant. */
 
511
  /** Is set if we have a GROUP BY and we have ORDER BY on a constant. */
471
512
  bool          skip_sort_order;
472
513
 
473
514
  bool need_tmp, hidden_group_fields;
481
522
  List<Item> &fields_list; ///< hold field list passed to mysql_select
482
523
  int error;
483
524
 
484
 
  order_st *order, *group_list, *proc_param; //hold parameters of mysql_select
 
525
  ORDER *order, *group_list, *proc_param; //hold parameters of mysql_select
485
526
  COND *conds;                            // ---"---
486
527
  Item *conds_history;                    // store WHERE for explain
487
 
  TableList *tables_list;           ///<hold 'tables' parameter of mysql_select
488
 
  List<TableList> *join_list;       ///< list of joined tables in reverse order
 
528
  TABLE_LIST *tables_list;           ///<hold 'tables' parameter of mysql_select
 
529
  List<TABLE_LIST> *join_list;       ///< list of joined tables in reverse order
489
530
  COND_EQUAL *cond_equal;
490
531
  SQL_SELECT *select;                ///<created in optimisation phase
491
532
  JOIN_TAB *return_tab;              ///<used only for outer joins
492
533
  Item **ref_pointer_array; ///<used pointer reference for this select
493
534
  // Copy of above to be used with different lists
494
535
  Item **items0, **items1, **items2, **items3, **current_ref_pointer_array;
495
 
  uint32_t ref_pointer_array_size; ///< size of above in bytes
 
536
  uint ref_pointer_array_size; ///< size of above in bytes
496
537
  const char *zero_result_cause; ///< not 0 if exec must return zero result
497
538
  
498
539
  bool union_part; ///< this subselect is part of union 
513
554
    excessive memory usage.
514
555
  */  
515
556
  SORT_FIELD *sortorder;                        // make_unireg_sortorder()
516
 
  Table **table_reexec;                         // make_simple_join()
 
557
  TABLE **table_reexec;                         // make_simple_join()
517
558
  JOIN_TAB *join_tab_reexec;                    // make_simple_join()
518
559
  /* end of allocation caching storage */
519
560
 
520
 
  JOIN(Session *session_arg, List<Item> &fields_arg, uint64_t select_options_arg,
 
561
  JOIN(THD *thd_arg, List<Item> &fields_arg, uint64_t select_options_arg,
521
562
       select_result *result_arg)
522
 
    :fields_list(fields_arg), sj_subselects(session_arg->mem_root, 4)
 
563
    :fields_list(fields_arg), sj_subselects(thd_arg->mem_root, 4)
523
564
  {
524
 
    init(session_arg, fields_arg, select_options_arg, result_arg);
 
565
    init(thd_arg, fields_arg, select_options_arg, result_arg);
525
566
  }
526
567
 
527
 
  void init(Session *session_arg, List<Item> &fields_arg, uint64_t select_options_arg,
 
568
  void init(THD *thd_arg, List<Item> &fields_arg, uint64_t select_options_arg,
528
569
       select_result *result_arg)
529
570
  {
530
571
    join_tab= join_tab_save= 0;
545
586
    sortorder= 0;
546
587
    table_reexec= 0;
547
588
    join_tab_reexec= 0;
548
 
    session= session_arg;
 
589
    thd= thd_arg;
549
590
    sum_funcs= sum_funcs2= 0;
550
591
    having= tmp_having= having_history= 0;
551
592
    select_options= select_options_arg;
552
593
    result= result_arg;
553
 
    lock= session_arg->lock;
 
594
    lock= thd_arg->lock;
554
595
    select_lex= 0; //for safety
555
596
    tmp_join= 0;
556
597
    select_distinct= test(select_options & SELECT_DISTINCT);
581
622
    no_const_tables= false;
582
623
  }
583
624
 
584
 
  int prepare(Item ***rref_pointer_array, TableList *tables, uint32_t wind_num,
585
 
              COND *conds, uint32_t og_num, order_st *order, order_st *group,
586
 
              Item *having, order_st *proc_param, SELECT_LEX *select,
 
625
  int prepare(Item ***rref_pointer_array, TABLE_LIST *tables, uint wind_num,
 
626
              COND *conds, uint og_num, ORDER *order, ORDER *group,
 
627
              Item *having, ORDER *proc_param, SELECT_LEX *select,
587
628
              SELECT_LEX_UNIT *unit);
588
629
  int optimize();
589
630
  int reinit();
611
652
  bool rollup_init();
612
653
  bool rollup_make_fields(List<Item> &all_fields, List<Item> &fields,
613
654
                          Item_sum ***func);
614
 
  int rollup_send_data(uint32_t idx);
615
 
  int rollup_write_data(uint32_t idx, Table *table);
 
655
  int rollup_send_data(uint idx);
 
656
  int rollup_write_data(uint idx, TABLE *table);
616
657
  void remove_subq_pushed_predicates(Item **where);
617
658
  /**
618
659
    Release memory and, if possible, the open tables held by this execution
634
675
  bool change_result(select_result *result);
635
676
  bool is_top_level_join() const
636
677
  {
637
 
    return (unit == &session->lex->unit && (unit->fake_select_lex == 0 ||
 
678
    return (unit == &thd->lex->unit && (unit->fake_select_lex == 0 ||
638
679
                                        select_lex == unit->fake_select_lex));
639
680
  }
640
681
};
641
682
 
642
683
 
643
684
typedef struct st_select_check {
644
 
  uint32_t const_ref,reg_ref;
 
685
  uint const_ref,reg_ref;
645
686
} SELECT_CHECK;
646
687
 
647
688
extern const char *join_type_str[];
649
690
 
650
691
/* Extern functions in sql_select.cc */
651
692
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
652
 
Table *create_tmp_table(Session *session,TMP_TABLE_PARAM *param,List<Item> &fields,
653
 
                        order_st *group, bool distinct, bool save_sum_fields,
 
693
TABLE *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
 
694
                        ORDER *group, bool distinct, bool save_sum_fields,
654
695
                        uint64_t select_options, ha_rows rows_limit,
655
696
                        char* alias);
656
 
void free_tmp_table(Session *session, Table *entry);
 
697
void free_tmp_table(THD *thd, TABLE *entry);
657
698
void count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param, 
658
699
                       List<Item> &fields, bool reset_with_sum_func);
659
 
bool setup_copy_fields(Session *session, TMP_TABLE_PARAM *param,
 
700
bool setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
660
701
                       Item **ref_pointer_array,
661
702
                       List<Item> &new_list1, List<Item> &new_list2,
662
 
                       uint32_t elements, List<Item> &fields);
 
703
                       uint elements, List<Item> &fields);
663
704
void copy_fields(TMP_TABLE_PARAM *param);
664
705
void copy_funcs(Item **func_ptr);
665
 
Field* create_tmp_field_from_field(Session *session, Field* org_field,
666
 
                                   const char *name, Table *table,
667
 
                                   Item_field *item, uint32_t convert_blob_length);
 
706
bool create_myisam_from_heap(THD *thd, TABLE *table,
 
707
                             MI_COLUMNDEF *start_recinfo,
 
708
                             MI_COLUMNDEF **recinfo, 
 
709
                             int error, bool ignore_last_dupp_key_error);
 
710
uint find_shortest_key(TABLE *table, const key_map *usable_keys);
 
711
Field* create_tmp_field_from_field(THD *thd, Field* org_field,
 
712
                                   const char *name, TABLE *table,
 
713
                                   Item_field *item, uint convert_blob_length);
668
714
                                                                      
669
715
/* functions from opt_sum.cc */
670
716
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
671
 
int opt_sum_query(TableList *tables, List<Item> &all_fields,COND *conds);
 
717
int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds);
672
718
 
673
719
/* from sql_delete.cc, used by opt_range.cc */
674
720
extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b);
680
726
public:
681
727
  bool null_key; /* true <=> the value of the key has a null part */
682
728
  enum store_key_result { STORE_KEY_OK, STORE_KEY_FATAL, STORE_KEY_CONV };
683
 
  store_key(Session *session, Field *field_arg, unsigned char *ptr, unsigned char *null, uint32_t length)
 
729
  store_key(THD *thd, Field *field_arg, uchar *ptr, uchar *null, uint length)
684
730
    :null_key(0), null_ptr(null), err(0)
685
731
  {
686
732
    if (field_arg->type() == DRIZZLE_TYPE_BLOB)
695
741
      to_field->init(field_arg->table);
696
742
    }
697
743
    else
698
 
      to_field=field_arg->new_key_field(session->mem_root, field_arg->table,
 
744
      to_field=field_arg->new_key_field(thd->mem_root, field_arg->table,
699
745
                                        ptr, null, 1);
700
746
  }
701
747
  virtual ~store_key() {}                       /** Not actually needed */
710
756
  enum store_key_result copy()
711
757
  {
712
758
    enum store_key_result result;
713
 
    Session *session= to_field->table->in_use;
714
 
    enum_check_fields saved_count_cuted_fields= session->count_cuted_fields;
 
759
    THD *thd= to_field->table->in_use;
 
760
    enum_check_fields saved_count_cuted_fields= thd->count_cuted_fields;
715
761
 
716
 
    session->count_cuted_fields= CHECK_FIELD_IGNORE;
 
762
    thd->count_cuted_fields= CHECK_FIELD_IGNORE;
717
763
 
718
764
    result= copy_inner();
719
765
 
720
 
    session->count_cuted_fields= saved_count_cuted_fields;
 
766
    thd->count_cuted_fields= saved_count_cuted_fields;
721
767
 
722
768
    return result;
723
769
  }
724
770
 
725
771
 protected:
726
772
  Field *to_field;                              // Store data here
727
 
  unsigned char *null_ptr;
728
 
  unsigned char err;
 
773
  uchar *null_ptr;
 
774
  uchar err;
729
775
 
730
776
  virtual enum store_key_result copy_inner()=0;
731
777
};
736
782
  Copy_field copy_field;
737
783
  const char *field_name;
738
784
 public:
739
 
  store_key_field(Session *session, Field *to_field_arg, unsigned char *ptr,
740
 
                  unsigned char *null_ptr_arg,
741
 
                  uint32_t length, Field *from_field, const char *name_arg)
742
 
    :store_key(session, to_field_arg,ptr,
 
785
  store_key_field(THD *thd, Field *to_field_arg, uchar *ptr,
 
786
                  uchar *null_ptr_arg,
 
787
                  uint length, Field *from_field, const char *name_arg)
 
788
    :store_key(thd, to_field_arg,ptr,
743
789
               null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
744
 
               : (unsigned char*) 0, length), field_name(name_arg)
 
790
               : (uchar*) 0, length), field_name(name_arg)
745
791
  {
746
792
    if (to_field)
747
793
    {
753
799
 protected: 
754
800
  enum store_key_result copy_inner()
755
801
  {
 
802
    TABLE *table= copy_field.to_field->table;
 
803
    my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
 
804
                                                     table->write_set);
756
805
    copy_field.do_copy(&copy_field);
 
806
    dbug_tmp_restore_column_map(table->write_set, old_map);
757
807
    null_key= to_field->is_null();
758
808
    return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
759
809
  }
765
815
 protected:
766
816
  Item *item;
767
817
public:
768
 
  store_key_item(Session *session, Field *to_field_arg, unsigned char *ptr,
769
 
                 unsigned char *null_ptr_arg, uint32_t length, Item *item_arg)
770
 
    :store_key(session, to_field_arg, ptr,
 
818
  store_key_item(THD *thd, Field *to_field_arg, uchar *ptr,
 
819
                 uchar *null_ptr_arg, uint length, Item *item_arg)
 
820
    :store_key(thd, to_field_arg, ptr,
771
821
               null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
772
 
               &err : (unsigned char*) 0, length), item(item_arg)
 
822
               &err : (uchar*) 0, length), item(item_arg)
773
823
  {}
774
824
  const char *name() const { return "func"; }
775
825
 
776
826
 protected:  
777
827
  enum store_key_result copy_inner()
778
828
  {
 
829
    TABLE *table= to_field->table;
 
830
    my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
 
831
                                                     table->write_set);
779
832
    int res= item->save_in_field(to_field, 1);
 
833
    dbug_tmp_restore_column_map(table->write_set, old_map);
780
834
    null_key= to_field->is_null() || item->null_value;
781
835
    return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res); 
782
836
  }
787
841
{
788
842
  bool inited;
789
843
public:
790
 
  store_key_const_item(Session *session, Field *to_field_arg, unsigned char *ptr,
791
 
                       unsigned char *null_ptr_arg, uint32_t length,
 
844
  store_key_const_item(THD *thd, Field *to_field_arg, uchar *ptr,
 
845
                       uchar *null_ptr_arg, uint length,
792
846
                       Item *item_arg)
793
 
    :store_key_item(session, to_field_arg,ptr,
 
847
    :store_key_item(thd, to_field_arg,ptr,
794
848
                    null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
795
 
                    &err : (unsigned char*) 0, length, item_arg), inited(0)
 
849
                    &err : (uchar*) 0, length, item_arg), inited(0)
796
850
  {
797
851
  }
798
852
  const char *name() const { return "const"; }
815
869
  }
816
870
};
817
871
 
818
 
bool cp_buffer_from_ref(Session *session, TABLE_REF *ref);
 
872
bool cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref);
819
873
bool error_if_full_join(JOIN *join);
 
874
int report_error(TABLE *table, int error);
820
875
int safe_index_read(JOIN_TAB *tab);
821
 
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);
 
876
COND *remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value);
822
877
int test_if_item_cache_changed(List<Cached_item> &list);