~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

  • Committer: Jay Pipes
  • Date: 2009-11-16 22:00:02 UTC
  • mto: (1234.1.1 push) (1237.2.10 push)
  • mto: This revision was merged to the branch mainline in revision 1229.
  • Revision ID: jpipes@serialcoder-20091116220002-rdsha64utt41i8w8
Adds INFORMATION_SCHEMA views for the transaction log:

TRANSACTION_LOG
TRANSACTION_LOG_ENTRIES
TRANSACTION_LOG_TRANSACTIONS

Adds a new user-defined function:

PRINT_TRANSACTION_MESSAGE(filename, offset)

Adds tests for all of the above

Implementation notes:

An indexer now runs when transaction messages are applied
to the transaction log.  It creates a simple index of the
transaction log entries.  This index is used when the
information schema views' fillTable() method is called.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/session.h>
23
23
#include <drizzled/table.h>
24
24
#include <drizzled/error.h>
25
 
#include <drizzled/join.h>
26
25
#include <drizzled/sql_base.h>
27
26
#include <drizzled/sql_select.h>
28
27
#include <drizzled/item/cmpfunc.h>
30
29
#include <drizzled/item/outer_ref.h>
31
30
#include <drizzled/plugin/client.h>
32
31
 
33
 
#include <boost/dynamic_bitset.hpp>
34
 
 
35
 
namespace drizzled
36
 
{
 
32
using namespace drizzled;
37
33
 
38
34
/**
39
35
  Store the pointer to this item field into a list if not already there.
86
82
 
87
83
bool Item_field::find_item_in_field_list_processor(unsigned char *arg)
88
84
{
89
 
  KeyPartInfo *first_non_group_part= *((KeyPartInfo **) arg);
90
 
  KeyPartInfo *last_part= *(((KeyPartInfo **) arg) + 1);
91
 
  KeyPartInfo *cur_part;
 
85
  KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
 
86
  KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
 
87
  KEY_PART_INFO *cur_part;
92
88
 
93
89
  for (cur_part= first_non_group_part; cur_part != last_part; cur_part++)
94
90
  {
110
106
bool Item_field::register_field_in_read_map(unsigned char *arg)
111
107
{
112
108
  Table *table= (Table *) arg;
113
 
  if (field->getTable() == table || !table)
114
 
    field->getTable()->setReadSet(field->position());
115
 
 
116
 
  return 0;
117
 
}
118
 
 
 
109
  if (field->table == table || !table)
 
110
    field->table->setReadSet(field->field_index);
 
111
 
 
112
  return 0;
 
113
}
 
114
 
 
115
 
 
116
Item_field *Item::filed_for_view_update()
 
117
{
 
118
  return 0;
 
119
}
119
120
 
120
121
Item_field::Item_field(Field *f)
121
 
  :Item_ident(0, NULL, f->getTable()->getAlias(), f->field_name),
 
122
  :Item_ident(0, NULL, *f->table_name, f->field_name),
122
123
   item_equal(0), no_const_subst(0),
123
124
   have_privileges(0), any_privileges(0)
124
125
{
138
139
  Item_field (this is important in prepared statements).
139
140
*/
140
141
 
141
 
Item_field::Item_field(Session *,
142
 
                       Name_resolution_context *context_arg,
143
 
                       Field *f) :
144
 
  Item_ident(context_arg,
145
 
             f->getTable()->getShare()->getSchemaName(),
146
 
             f->getTable()->getAlias(),
147
 
             f->field_name),
148
 
   item_equal(0),
149
 
   no_const_subst(0),
150
 
   have_privileges(0),
151
 
   any_privileges(0)
 
142
Item_field::Item_field(Session *, Name_resolution_context *context_arg,
 
143
                       Field *f)
 
144
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
 
145
   item_equal(0), no_const_subst(0),
 
146
   have_privileges(0), any_privileges(0)
152
147
{
153
148
  set_field(f);
154
149
}
156
151
 
157
152
Item_field::Item_field(Name_resolution_context *context_arg,
158
153
                       const char *db_arg,const char *table_name_arg,
159
 
                       const char *field_name_arg) :
160
 
  Item_ident(context_arg, db_arg,table_name_arg,field_name_arg),
161
 
   field(0),
162
 
   result_field(0),
163
 
   item_equal(0),
164
 
   no_const_subst(0),
165
 
   have_privileges(0),
166
 
   any_privileges(0)
 
154
                       const char *field_name_arg)
 
155
  :Item_ident(context_arg, db_arg,table_name_arg,field_name_arg),
 
156
   field(0), result_field(0), item_equal(0), no_const_subst(0),
 
157
   have_privileges(0), any_privileges(0)
167
158
{
168
159
  Select_Lex *select= current_session->lex->current_select;
169
160
  collation.set(DERIVATION_IMPLICIT);
170
 
 
171
161
  if (select && select->parsing_place != IN_HAVING)
172
162
      select->select_n_where_fields++;
173
163
}
176
166
  Constructor need to process subselect with temporary tables (see Item)
177
167
*/
178
168
 
179
 
Item_field::Item_field(Session *session, Item_field *item) :
180
 
  Item_ident(session, item),
181
 
  field(item->field),
182
 
  result_field(item->result_field),
183
 
  item_equal(item->item_equal),
184
 
  no_const_subst(item->no_const_subst),
185
 
  have_privileges(item->have_privileges),
186
 
  any_privileges(item->any_privileges)
 
169
Item_field::Item_field(Session *session, Item_field *item)
 
170
  :Item_ident(session, item),
 
171
   field(item->field),
 
172
   result_field(item->result_field),
 
173
   item_equal(item->item_equal),
 
174
   no_const_subst(item->no_const_subst),
 
175
   have_privileges(item->have_privileges),
 
176
   any_privileges(item->any_privileges)
187
177
{
188
178
  collation.set(DERIVATION_IMPLICIT);
189
179
}
194
184
  maybe_null=field->maybe_null();
195
185
  decimals= field->decimals();
196
186
  max_length= field_par->max_display_length();
197
 
  table_name= field_par->getTable()->getAlias();
 
187
  table_name= *field_par->table_name;
198
188
  field_name= field_par->field_name;
199
 
  db_name= field_par->getTable()->getShare()->getSchemaName();
200
 
  alias_name_used= field_par->getTable()->alias_name_used;
 
189
  db_name= field_par->table->s->db.str;
 
190
  alias_name_used= field_par->table->alias_name_used;
201
191
  unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
202
192
  collation.set(field_par->charset(), field_par->derivation());
203
193
  fixed= 1;
 
194
  if (field->table->s->tmp_table == SYSTEM_TMP_TABLE)
 
195
    any_privileges= 0;
204
196
}
205
197
 
206
198
 
323
315
  switch (result_field->result_type()) {
324
316
  case INT_RESULT:
325
317
    return result_field->val_int() != 0;
326
 
 
327
318
  case DECIMAL_RESULT:
328
 
    {
329
 
      my_decimal decimal_value;
330
 
      my_decimal *val= result_field->val_decimal(&decimal_value);
331
 
      if (val)
332
 
        return !my_decimal_is_zero(val);
333
 
      return 0;
334
 
    }
335
 
 
 
319
  {
 
320
    my_decimal decimal_value;
 
321
    my_decimal *val= result_field->val_decimal(&decimal_value);
 
322
    if (val)
 
323
      return !my_decimal_is_zero(val);
 
324
    return 0;
 
325
  }
336
326
  case REAL_RESULT:
337
327
  case STRING_RESULT:
338
328
    return result_field->val_real() != 0.0;
339
 
 
340
329
  case ROW_RESULT:
 
330
  default:
341
331
    assert(0);
342
332
    return 0;                                   // Shut up compiler
343
333
  }
344
 
 
345
 
  assert(0);
346
 
  return 0;                                   // Shut up compiler
347
334
}
348
335
 
349
336
 
372
359
           (!my_strcasecmp(table_alias_charset, item_field->table_name,
373
360
                           table_name) &&
374
361
            (!item_field->db_name || !db_name ||
375
 
             (item_field->db_name && !strcasecmp(item_field->db_name,
 
362
             (item_field->db_name && !strcmp(item_field->db_name,
376
363
                                             db_name))))));
377
364
}
378
365
 
379
366
 
380
367
table_map Item_field::used_tables() const
381
368
{
382
 
  if (field->getTable()->const_table)
 
369
  if (field->table->const_table)
383
370
    return 0;                                   // const item
384
 
  return (depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map);
 
371
  return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map);
385
372
}
386
373
 
387
374
enum Item_result Item_field::result_type () const
537
524
      {
538
525
        if (*from_field != view_ref_found)
539
526
        {
540
 
          prev_subselect_item->used_tables_cache|= (*from_field)->getTable()->map;
 
527
          prev_subselect_item->used_tables_cache|= (*from_field)->table->map;
541
528
          prev_subselect_item->const_item_cache= 0;
542
529
          set_field(*from_field);
543
530
          if (!last_checked_context->select_lex->having_fix_field &&
704
691
    {
705
692
      Item_ref *rf;
706
693
      rf= new Item_ref(context,
707
 
                       (cached_table->getSchemaName()[0] ? cached_table->getSchemaName() : 0),
 
694
                       (cached_table->db[0] ? cached_table->db : 0),
708
695
                       (char*) cached_table->alias, (char*) field_name);
709
696
      if (!rf)
710
697
        return -1;
796
783
      {
797
784
        uint32_t counter;
798
785
        enum_resolution_type resolution;
799
 
        Item** res= find_item_in_list(session,
800
 
                                      this, session->lex->current_select->item_list,
 
786
        Item** res= find_item_in_list(this, session->lex->current_select->item_list,
801
787
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
802
788
                                      &resolution);
803
789
        if (!res)
895
881
  }
896
882
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
897
883
  {
898
 
    Table *table= field->getTable();
899
 
    boost::dynamic_bitset<> *current_bitmap, *other_bitmap;
 
884
    Table *table= field->table;
 
885
    MyBitmap *current_bitmap, *other_bitmap;
900
886
    if (session->mark_used_columns == MARK_COLUMNS_READ)
901
887
    {
902
888
      current_bitmap= table->read_set;
907
893
      current_bitmap= table->write_set;
908
894
      other_bitmap=   table->read_set;
909
895
    }
910
 
    //if (! current_bitmap->testAndSet(field->position()))
911
 
    if (! current_bitmap->test(field->position()))
 
896
    if (! current_bitmap->testAndSet(field->field_index))
912
897
    {
913
 
      if (! other_bitmap->test(field->position()))
 
898
      if (! other_bitmap->isBitSet(field->field_index))
914
899
      {
915
900
        /* First usage of column */
916
901
        table->used_fields++;                     // Used to optimize loops
1208
1193
    need to set no_errors to prevent warnings about type conversion
1209
1194
    popping up.
1210
1195
  */
1211
 
  Session *session= field->getTable()->in_use;
 
1196
  Session *session= field->table->in_use;
1212
1197
  int no_errors;
1213
1198
 
1214
1199
  no_errors= session->no_errors;
1245
1230
  Select_Lex *select= (Select_Lex*)select_arg;
1246
1231
  assert(fixed);
1247
1232
 
1248
 
  if (field->getTable() != select->context.table_list->table)
 
1233
  if (field->table != select->context.table_list->table)
1249
1234
  {
1250
1235
    List<Item> *all_fields= &select->join->all_fields;
1251
1236
    Item **ref_pointer_array= select->ref_pointer_array;
1264
1249
 
1265
1250
void Item_field::print(String *str, enum_query_type query_type)
1266
1251
{
1267
 
  if (field && field->getTable()->const_table)
 
1252
  if (field && field->table->const_table)
1268
1253
  {
1269
1254
    char buff[MAX_FIELD_WIDTH];
1270
1255
    String tmp(buff,sizeof(buff),str->charset());
1271
 
    field->val_str_internal(&tmp);
1272
 
    if (field->is_null())  {
1273
 
      str->append("NULL");
1274
 
    }
1275
 
    else {
1276
 
      str->append('\'');
1277
 
      str->append(tmp);
1278
 
      str->append('\'');
1279
 
    }
 
1256
    field->val_str(&tmp);
 
1257
    str->append('\'');
 
1258
    str->append(tmp);
 
1259
    str->append('\'');
1280
1260
    return;
1281
1261
  }
1282
1262
  Item_ident::print(str, query_type);
1283
1263
}
1284
 
 
1285
 
 
1286
 
} /* namespace drizzled */