~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/schema_engine.cc

  • Committer: Prafulla Tekawade
  • Date: 2010-08-06 11:21:12 UTC
  • mto: (1711.1.21 build) (1725.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1714.
  • Revision ID: prafulla_t@users.sourceforge.net-20100806112112-7w5u0s3nx9u67nzt
Fix for Bug 586051

1. test_if_ref method which checks whether predicate is already evaluated
   due to ref/eq_ref access or not was incorrectly removing a predicate 
   that was not implicitly evaluated due to ref access (due to presence of filesort ?)
   It was field=NULL predicate.
   Such predicate should be kept and execution engine will filter out rows
   correctly. Removal of such predicate led to returning of rows which had
   NULL for join/predicate columns.
2. field COMP_OP NULL will always false for all fields except when COMP_OP
   is NULL-safe equality operator. Modified range optimizer to return zero
   row count in such cases.
   Query now does not even run. It returns zero result. As such Fix(1) is not
   required but we might hit that case in some other query (I have not tried it
   yet)
3. Fixed Field::val_str to print "NULL" for literal NULL instead of "0". It
   added lot of confusion while debugging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include "drizzled/global_charset_info.h"
25
25
#include "drizzled/charset.h"
26
 
#include "drizzled/transaction_services.h"
27
26
 
28
27
#include "drizzled/plugin/storage_engine.h"
29
28
#include "drizzled/plugin/authorization.h"
30
29
 
 
30
using namespace std;
 
31
 
31
32
namespace drizzled
32
33
{
33
34
 
35
36
{
36
37
 
37
38
class AddSchemaNames : 
38
 
  public std::unary_function<StorageEngine *, void>
 
39
  public unary_function<StorageEngine *, void>
39
40
{
40
 
  SchemaIdentifier::vector &schemas;
 
41
  SchemaIdentifiers &schemas;
41
42
 
42
43
public:
43
44
 
44
 
  AddSchemaNames(SchemaIdentifier::vector &of_names) :
 
45
  AddSchemaNames(SchemaIdentifiers &of_names) :
45
46
    schemas(of_names)
46
47
  {
47
48
  }
52
53
  }
53
54
};
54
55
 
55
 
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifier::vector &schemas)
 
56
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifiers &schemas)
56
57
{
57
58
  // Add hook here for engines to register schema.
58
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
59
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
59
60
           AddSchemaNames(schemas));
60
61
 
61
62
  plugin::Authorization::pruneSchemaNames(session.getSecurityContext(), schemas);
62
63
}
63
64
 
64
 
class StorageEngineGetSchemaDefinition: public std::unary_function<StorageEngine *, bool>
 
65
class StorageEngineGetSchemaDefinition: public unary_function<StorageEngine *, bool>
65
66
{
66
67
  const SchemaIdentifier &identifier;
67
 
  message::schema::shared_ptr &schema_proto;
 
68
  message::Schema &schema_proto;
68
69
 
69
70
public:
70
71
  StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg,
71
 
                                   message::schema::shared_ptr &schema_proto_arg) :
 
72
                                   message::Schema &schema_proto_arg) :
72
73
    identifier(identifier_arg),
73
74
    schema_proto(schema_proto_arg) 
74
75
  {
83
84
/*
84
85
  Return value is "if parsed"
85
86
*/
86
 
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::schema::shared_ptr &proto)
 
87
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::Schema &proto)
87
88
{
88
89
  return StorageEngine::getSchemaDefinition(identifier, proto);
89
90
}
90
91
 
91
 
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::schema::shared_ptr &proto)
 
92
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::Schema &proto)
92
93
{
 
94
  proto.Clear();
 
95
 
93
96
  EngineVector::iterator iter=
94
 
    std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
95
 
                 StorageEngineGetSchemaDefinition(identifier, proto));
 
97
    find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
98
            StorageEngineGetSchemaDefinition(identifier, proto));
96
99
 
97
100
  if (iter != StorageEngine::getSchemaEngines().end())
98
101
  {
104
107
 
105
108
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier)
106
109
{
107
 
  message::schema::shared_ptr proto;
 
110
  message::Schema proto;
108
111
 
109
112
  return StorageEngine::getSchemaDefinition(identifier, proto);
110
113
}
112
115
 
113
116
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier)
114
117
{
115
 
  message::schema::shared_ptr schmema_proto;
 
118
  message::Schema schmema_proto;
116
119
  bool found;
117
120
 
118
121
  found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
119
122
 
120
 
  if (found && schmema_proto->has_collation())
 
123
  if (found && schmema_proto.has_collation())
121
124
  {
122
 
    const std::string buffer= schmema_proto->collation();
 
125
    const string buffer= schmema_proto.collation();
123
126
    const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
124
127
 
125
128
    if (not cs)
126
129
    {
127
 
      std::string path;
128
 
      identifier.getSQLPath(path);
129
 
 
130
130
      errmsg_printf(ERRMSG_LVL_ERROR,
131
 
                    _("Error while loading database options: '%s':"), path.c_str());
 
131
                    _("Error while loading database options: '%s':"), const_cast<SchemaIdentifier &>(identifier).getSQLPath().c_str());
132
132
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
133
133
 
134
134
      return default_charset_info;
141
141
}
142
142
 
143
143
class CreateSchema : 
144
 
  public std::unary_function<StorageEngine *, void>
 
144
  public unary_function<StorageEngine *, void>
145
145
{
146
146
  const drizzled::message::Schema &schema_message;
147
147
 
155
155
  result_type operator() (argument_type engine)
156
156
  {
157
157
    // @todo eomeday check that at least one engine said "true"
158
 
    bool success= engine->doCreateSchema(schema_message);
159
 
 
160
 
    if (success) 
161
 
    {
162
 
      TransactionServices &transaction_services= TransactionServices::singleton();
163
 
      transaction_services.allocateNewTransactionId();
164
 
    }
 
158
    (void)engine->doCreateSchema(schema_message);
165
159
  }
166
160
};
167
161
 
168
162
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
169
163
{
170
164
  // Add hook here for engines to register schema.
171
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
172
 
                CreateSchema(schema_message));
 
165
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
166
           CreateSchema(schema_message));
173
167
 
174
168
  return true;
175
169
}
176
170
 
177
171
class DropSchema : 
178
 
  public std::unary_function<StorageEngine *, void>
 
172
  public unary_function<StorageEngine *, void>
179
173
{
180
174
  uint64_t &success_count;
181
175
  const SchemaIdentifier &identifier;
194
188
    bool success= engine->doDropSchema(identifier);
195
189
 
196
190
    if (success)
197
 
    {
198
191
      success_count++;
199
 
      TransactionServices &transaction_services= TransactionServices::singleton();
200
 
      transaction_services.allocateNewTransactionId();
201
 
    }
202
192
  }
203
193
};
204
194
 
206
196
{
207
197
  uint64_t counter= 0;
208
198
  // Add hook here for engines to register schema.
209
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
210
 
                DropSchema(identifier, counter));
 
199
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
200
           DropSchema(identifier, counter));
211
201
 
212
202
  return counter ? true : false;
213
203
}
214
204
 
215
205
class AlterSchema : 
216
 
  public std::unary_function<StorageEngine *, void>
 
206
  public unary_function<StorageEngine *, void>
217
207
{
218
208
  uint64_t &success_count;
219
209
  const drizzled::message::Schema &schema_message;
231
221
    // @todo eomeday check that at least one engine said "true"
232
222
    bool success= engine->doAlterSchema(schema_message);
233
223
 
234
 
 
235
224
    if (success)
236
 
    {
237
225
      success_count++;
238
 
      TransactionServices &transaction_services= TransactionServices::singleton();
239
 
      transaction_services.allocateNewTransactionId();
240
 
    }
241
226
  }
242
227
};
243
228
 
245
230
{
246
231
  uint64_t success_count= 0;
247
232
 
248
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
249
 
                AlterSchema(schema_message, success_count));
 
233
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
234
           AlterSchema(schema_message, success_count));
250
235
 
251
236
  return success_count ? true : false;
252
237
}