~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_olap.cc

  • Committer: Stewart Smith
  • Date: 2008-07-13 08:00:16 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713080016-8qtjv9ypt42azzr6
CRC32() as UDF

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
*/
27
27
 
28
28
#ifdef DISABLED_UNTIL_REWRITTEN_IN_4_1
29
 
#include <drizzled/server_includes.h>
30
 
#include <drizzled/sql_select.h>
 
29
 
 
30
#ifdef USE_PRAGMA_IMPLEMENTATION
 
31
#pragma implementation                          // gcc: Class implementation
 
32
#endif
 
33
 
 
34
#include "mysql_priv.h"
 
35
#include "sql_select.h"
31
36
 
32
37
 
33
38
/****************************************************************************
36
41
****************************************************************************/
37
42
 
38
43
 
39
 
static int make_new_olap_select(LEX *lex, Select_Lex *select_lex, List<Item> new_fields)
 
44
static int make_new_olap_select(LEX *lex, SELECT_LEX *select_lex, List<Item> new_fields)
40
45
{
41
 
  Session       *session=current_session;
 
46
  THD   *thd=current_thd;
42
47
  Item *item, *new_item;
43
48
  Item_null *constant= new Item_null("ALL");
44
49
 
45
 
  Select_Lex *new_select = (Select_Lex *) session->memdup((char*) select_lex, sizeof(*select_lex));
 
50
  SELECT_LEX *new_select = (SELECT_LEX *) thd->memdup((char*) select_lex, sizeof(*select_lex));
46
51
  if (!new_select)
47
52
    return 1;
48
53
  lex->last_selects->next=new_select;
49
54
  new_select->linkage=OLAP_TYPE;
50
55
  new_select->olap=NON_EXISTING_ONE;
51
56
  new_select->group_list.elements=0;
52
 
  new_select->group_list.first=(unsigned char *)0;
53
 
  new_select->group_list.next=(unsigned char **)&new_select->group_list.first;
 
57
  new_select->group_list.first=(uchar *)0;
 
58
  new_select->group_list.next=(uchar **)&new_select->group_list.first;
54
59
  List<Item> privlist;
55
 
 
 
60
  
56
61
  List_iterator<Item> list_it(select_lex->item_list);
57
62
  List_iterator<Item> new_it(new_fields);
58
 
 
 
63
    
59
64
  while ((item=list_it++))
60
65
  {
61
66
    bool not_found= true;
65
70
      new_it.rewind();
66
71
      while ((new_item=new_it++))
67
72
      {
68
 
        if (new_item->type()==Item::FIELD_ITEM &&
 
73
        if (new_item->type()==Item::FIELD_ITEM && 
69
74
            !strcmp(((Item_field*)new_item)->table_name,iif->table_name) &&
70
75
            !strcmp(((Item_field*)new_item)->field_name,iif->field_name))
71
76
        {
85
90
      if (item->type() == Item::FIELD_ITEM)
86
91
        privlist.push_back(constant);
87
92
      else
88
 
        privlist.push_back((Item*)session->memdup((char *)item,item->size_of()));
 
93
        privlist.push_back((Item*)thd->memdup((char *)item,item->size_of()));
89
94
    }
90
95
  }
91
96
  new_select->item_list=privlist;
99
104
  Returns 0 if OK, 1 if error, -1 if error already printed to client
100
105
****************************************************************************/
101
106
 
102
 
static int  olap_combos(List<Item> old_fields, List<Item> new_fields, Item *item, LEX *lex,
103
 
                              Select_Lex *select_lex, int position, int selection, int num_fields,
 
107
static int  olap_combos(List<Item> old_fields, List<Item> new_fields, Item *item, LEX *lex, 
 
108
                              SELECT_LEX *select_lex, int position, int selection, int num_fields, 
104
109
                              int num_new_fields)
105
110
{
106
111
  int sl_return = 0;
126
131
 
127
132
/****************************************************************************
128
133
  Top level function for converting OLAP clauses to multiple selects
129
 
  This is also a place where clauses treatment depends on OLAP type
 
134
  This is also a place where clauses treatment depends on OLAP type 
130
135
  Returns 0 if OK, 1 if error, -1 if error already printed to client
131
136
****************************************************************************/
132
137
 
133
 
int handle_olaps(LEX *lex, Select_Lex *select_lex)
 
138
int handle_olaps(LEX *lex, SELECT_LEX *select_lex)
134
139
{
135
140
  List<Item> item_list_copy, new_item_list;
136
141
  item_list_copy.empty();
147
152
  List<Item>    all_fields(select_lex->item_list);
148
153
 
149
154
 
150
 
  if (setup_tables(lex->session, &select_lex->context, &select_lex->top_join_list,
151
 
                   (TableList *)select_lex->table_list.first
 
155
  if (setup_tables(lex->thd, &select_lex->context, &select_lex->top_join_list,
 
156
                   (TABLE_LIST *)select_lex->table_list.first
152
157
                   &select_lex->leaf_tables, false) ||
153
 
      setup_fields(lex->session, 0, select_lex->item_list, MARK_COLUMNS_READ,
 
158
      setup_fields(lex->thd, 0, select_lex->item_list, MARK_COLUMNS_READ,
154
159
                   &all_fields,1) ||
155
 
      setup_fields(lex->session, 0, item_list_copy, MARK_COLUMNS_READ,
 
160
      setup_fields(lex->thd, 0, item_list_copy, MARK_COLUMNS_READ,
156
161
                   &all_fields, 1))
157
162
    return -1;
158
163