1
/* Copyright (C) 2000-2006 MySQL AB
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.
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.
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 */
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
21
24
classes to use when handling where clause
24
#ifdef USE_PRAGMA_INTERFACE
25
#pragma interface /* gcc class implementation */
28
28
/* PREV_BITS only used in sql_select.cc */
29
29
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
31
31
#include <storage/myisam/myisam.h>
32
#include <drizzled/sql_array.h>
33
34
/* Values in optimize */
34
35
#define KEY_OPTIMIZE_EXISTS 1
281
282
NULL - Not an insideout scan.
283
284
struct st_join_table *insideout_match_tab;
284
uchar *insideout_buf; // Buffer to save index tuple to be able to skip dups
285
unsigned char *insideout_buf; // Buffer to save index tuple to be able to skip dups
286
287
/* Used by InsideOut scan. Just set to true when have found a row. */
287
288
bool found_match;
383
384
Table *sort_by_table;
384
385
uint tables; /**< Number of tables in the join */
385
uint outer_tables; /**< Number of tables that are not inside semijoin */
386
uint32_t outer_tables; /**< Number of tables that are not inside semijoin */
387
uint32_t const_tables;
387
388
uint send_group_parts;
388
389
bool sort_and_group,first_record,full_join,group, no_field_update;
389
390
bool do_send_rows;
418
419
Table *tmp_table;
419
420
/// used to store 2 possible tmp table of SELECT
420
421
Table *exec_tmp_table1, *exec_tmp_table2;
422
423
Item_sum **sum_funcs, ***sum_funcs_end;
423
424
/** second copy of sumfuncs (for queries with 2 temporary tables */
424
425
Item_sum **sum_funcs2, ***sum_funcs_end2;
491
492
Item **ref_pointer_array; ///<used pointer reference for this select
492
493
// Copy of above to be used with different lists
493
494
Item **items0, **items1, **items2, **items3, **current_ref_pointer_array;
494
uint ref_pointer_array_size; ///< size of above in bytes
495
uint32_t ref_pointer_array_size; ///< size of above in bytes
495
496
const char *zero_result_cause; ///< not 0 if exec must return zero result
497
498
bool union_part; ///< this subselect is part of union
516
517
JOIN_TAB *join_tab_reexec; // make_simple_join()
517
518
/* end of allocation caching storage */
519
JOIN(THD *thd_arg, List<Item> &fields_arg, uint64_t select_options_arg,
520
JOIN(Session *session_arg, List<Item> &fields_arg, uint64_t select_options_arg,
520
521
select_result *result_arg)
521
:fields_list(fields_arg), sj_subselects(thd_arg->mem_root, 4)
522
:fields_list(fields_arg), sj_subselects(session_arg->mem_root, 4)
523
init(thd_arg, fields_arg, select_options_arg, result_arg);
524
init(session_arg, fields_arg, select_options_arg, result_arg);
526
void init(THD *thd_arg, List<Item> &fields_arg, uint64_t select_options_arg,
527
void init(Session *session_arg, List<Item> &fields_arg, uint64_t select_options_arg,
527
528
select_result *result_arg)
529
530
join_tab= join_tab_save= 0;
580
581
no_const_tables= false;
583
int prepare(Item ***rref_pointer_array, TableList *tables, uint wind_num,
584
COND *conds, uint og_num, order_st *order, order_st *group,
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,
585
586
Item *having, order_st *proc_param, SELECT_LEX *select,
586
587
SELECT_LEX_UNIT *unit);
610
611
bool rollup_init();
611
612
bool rollup_make_fields(List<Item> &all_fields, List<Item> &fields,
612
613
Item_sum ***func);
613
int rollup_send_data(uint idx);
614
int rollup_write_data(uint idx, Table *table);
614
int rollup_send_data(uint32_t idx);
615
int rollup_write_data(uint32_t idx, Table *table);
615
616
void remove_subq_pushed_predicates(Item **where);
617
618
Release memory and, if possible, the open tables held by this execution
633
634
bool change_result(select_result *result);
634
635
bool is_top_level_join() const
636
return (unit == &thd->lex->unit && (unit->fake_select_lex == 0 ||
637
return (unit == &session->lex->unit && (unit->fake_select_lex == 0 ||
637
638
select_lex == unit->fake_select_lex));
642
643
typedef struct st_select_check {
643
uint const_ref,reg_ref;
644
uint32_t const_ref,reg_ref;
646
647
extern const char *join_type_str[];
649
650
/* Extern functions in sql_select.cc */
650
651
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
Table *create_tmp_table(Session *session,TMP_TABLE_PARAM *param,List<Item> &fields,
652
653
order_st *group, bool distinct, bool save_sum_fields,
653
654
uint64_t select_options, ha_rows rows_limit,
655
void free_tmp_table(THD *thd, Table *entry);
656
void free_tmp_table(Session *session, Table *entry);
656
657
void count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param,
657
658
List<Item> &fields, bool reset_with_sum_func);
658
bool setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
659
bool setup_copy_fields(Session *session, TMP_TABLE_PARAM *param,
659
660
Item **ref_pointer_array,
660
661
List<Item> &new_list1, List<Item> &new_list2,
661
uint elements, List<Item> &fields);
662
uint32_t elements, List<Item> &fields);
662
663
void copy_fields(TMP_TABLE_PARAM *param);
663
664
void copy_funcs(Item **func_ptr);
664
Field* create_tmp_field_from_field(THD *thd, Field* org_field,
665
Field* create_tmp_field_from_field(Session *session, Field* org_field,
665
666
const char *name, Table *table,
666
Item_field *item, uint convert_blob_length);
667
Item_field *item, uint32_t convert_blob_length);
668
669
/* functions from opt_sum.cc */
669
670
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
680
681
bool null_key; /* true <=> the value of the key has a null part */
681
682
enum store_key_result { STORE_KEY_OK, STORE_KEY_FATAL, STORE_KEY_CONV };
682
store_key(THD *thd, Field *field_arg, uchar *ptr, uchar *null, uint length)
683
store_key(Session *session, Field *field_arg, unsigned char *ptr, unsigned char *null, uint32_t length)
683
684
:null_key(0), null_ptr(null), err(0)
685
686
if (field_arg->type() == DRIZZLE_TYPE_BLOB)
694
695
to_field->init(field_arg->table);
697
to_field=field_arg->new_key_field(thd->mem_root, field_arg->table,
698
to_field=field_arg->new_key_field(session->mem_root, field_arg->table,
700
701
virtual ~store_key() {} /** Not actually needed */
709
710
enum store_key_result copy()
711
712
enum store_key_result result;
712
THD *thd= to_field->table->in_use;
713
enum_check_fields saved_count_cuted_fields= thd->count_cuted_fields;
713
Session *session= to_field->table->in_use;
714
enum_check_fields saved_count_cuted_fields= session->count_cuted_fields;
715
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
716
session->count_cuted_fields= CHECK_FIELD_IGNORE;
717
718
result= copy_inner();
719
thd->count_cuted_fields= saved_count_cuted_fields;
720
session->count_cuted_fields= saved_count_cuted_fields;
725
726
Field *to_field; // Store data here
727
unsigned char *null_ptr;
729
730
virtual enum store_key_result copy_inner()=0;
735
736
Copy_field copy_field;
736
737
const char *field_name;
738
store_key_field(THD *thd, Field *to_field_arg, uchar *ptr,
740
uint length, Field *from_field, const char *name_arg)
741
:store_key(thd, to_field_arg,ptr,
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,
742
743
null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
743
: (uchar*) 0, length), field_name(name_arg)
744
: (unsigned char*) 0, length), field_name(name_arg)
767
store_key_item(THD *thd, Field *to_field_arg, uchar *ptr,
768
uchar *null_ptr_arg, uint length, Item *item_arg)
769
:store_key(thd, to_field_arg, ptr,
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,
770
771
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
771
&err : (uchar*) 0, length), item(item_arg)
772
&err : (unsigned char*) 0, length), item(item_arg)
773
774
const char *name() const { return "func"; }
789
store_key_const_item(THD *thd, Field *to_field_arg, uchar *ptr,
790
uchar *null_ptr_arg, uint length,
790
store_key_const_item(Session *session, Field *to_field_arg, unsigned char *ptr,
791
unsigned char *null_ptr_arg, uint32_t length,
792
:store_key_item(thd, to_field_arg,ptr,
793
:store_key_item(session, to_field_arg,ptr,
793
794
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
794
&err : (uchar*) 0, length, item_arg), inited(0)
795
&err : (unsigned char*) 0, length, item_arg), inited(0)
797
798
const char *name() const { return "const"; }
817
bool cp_buffer_from_ref(THD *thd, TABLE_REF *ref);
818
bool cp_buffer_from_ref(Session *session, TABLE_REF *ref);
818
819
bool error_if_full_join(JOIN *join);
819
820
int safe_index_read(JOIN_TAB *tab);
820
COND *remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value);
821
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);
821
822
int test_if_item_cache_changed(List<Cached_item> &list);