~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/function.cc

  • Committer: Prafulla Tekawade
  • Date: 2010-07-13 16:07:35 UTC
  • mto: (1662.1.4 rollup)
  • mto: This revision was merged to the branch mainline in revision 1664.
  • Revision ID: prafulla_t@users.sourceforge.net-20100713160735-2fsdtrm3azayuyu1
This bug is simillar to mysql bug 36133
http://bugs.mysql.com/bug.php?id=36133

Taking changes from that fix.

  - The problem was that the range optimizer evaluated constant expressions, 
    and among them it would try to evaluate IN-subquery predicates slated for
    handling with materialization strategy. However, these predicates require
    that parent_join->setup_subquery_materialization() is invoked before one
    attempts to evaluate them.
  
  - Fixed by making the range optimizer not to evaluate expressions that have
    item->is_expensive() == TRUE (these are materialization subqueries and 
    stored function calls). This should also resolve the problem that EXPLAIN 
    may be too long. 
    This change cuts off some opportunities for range optimizer, but this is 
    the price we're willing to pay for separation of query optimization and
    execution. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2010 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2010 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
 
23
23
#include <plugin/function_engine/function.h>
24
24
#include <plugin/function_engine/cursor.h>
28
28
using namespace std;
29
29
using namespace drizzled;
30
30
 
 
31
static SchemaIdentifier INFORMATION_SCHEMA_IDENTIFIER("INFORMATION_SCHEMA");
 
32
static SchemaIdentifier DATA_DICTIONARY_IDENTIFIER("DATA_DICTIONARY");
 
33
 
31
34
Function::Function(const std::string &name_arg) :
32
35
  drizzled::plugin::StorageEngine(name_arg,
33
36
                                  HTON_ALTER_NOT_SUPPORTED |
34
37
                                  HTON_HAS_SCHEMA_DICTIONARY |
35
38
                                  HTON_SKIP_STORE_LOCK |
36
 
                                  HTON_TEMPORARY_NOT_SUPPORTED),
37
 
  information_message(new(message::Schema)),
38
 
  data_dictionary_message(new(message::Schema))
39
 
 
 
39
                                  HTON_TEMPORARY_NOT_SUPPORTED)
40
40
{
41
 
  information_message->set_name(INFORMATION_SCHEMA_IDENTIFIER.getSchemaName());
42
 
  information_message->set_collation("utf8_general_ci");
43
 
  information_message->mutable_replication_options()->set_dont_replicate(true);
44
 
 
45
 
  data_dictionary_message->set_name(DATA_DICTIONARY_IDENTIFIER.getSchemaName());
46
 
  data_dictionary_message->set_collation("utf8_general_ci");
47
 
  data_dictionary_message->mutable_replication_options()->set_dont_replicate(true);
48
41
}
49
42
 
50
43
 
51
 
Cursor *Function::create(Table &table)
 
44
Cursor *Function::create(TableShare &table, memory::Root *mem_root)
52
45
{
53
 
  return new FunctionCursor(*this, table);
 
46
  return new (mem_root) FunctionCursor(*this, table);
54
47
}
55
48
 
56
49
int Function::doGetTableDefinition(Session &,
57
 
                                   const identifier::Table &identifier,
 
50
                                   const TableIdentifier &identifier,
58
51
                                   message::Table &table_proto)
59
52
{
60
 
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
 
53
  string tab_name(identifier.getPath());
 
54
  transform(tab_name.begin(), tab_name.end(),
 
55
            tab_name.begin(), ::tolower);
 
56
 
 
57
  drizzled::plugin::TableFunction *function= getFunction(tab_name);
61
58
 
62
59
  if (not function)
63
60
  {
69
66
  return EEXIST;
70
67
}
71
68
 
72
 
void Function::doGetSchemaIdentifiers(identifier::Schema::vector& schemas)
 
69
 
 
70
void Function::doGetTableNames(drizzled::CachedDirectory&, 
 
71
                               const drizzled::SchemaIdentifier &schema_identifier,
 
72
                               set<string> &set_of_names)
 
73
{
 
74
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
 
75
}
 
76
 
 
77
void Function::doGetSchemaIdentifiers(SchemaIdentifierList& schemas)
73
78
{
74
79
  schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
75
80
  schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
76
81
}
77
82
 
78
 
drizzled::message::schema::shared_ptr Function::doGetSchemaDefinition(const identifier::Schema &schema_identifier)
 
83
bool Function::doGetSchemaDefinition(const SchemaIdentifier &schema_identifier, message::Schema &schema_message)
79
84
{
80
 
  drizzled::message::schema::shared_ptr schema_message;
81
 
 
82
85
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
83
86
  {
84
 
    schema_message= information_message;
 
87
    schema_message.set_name("information_schema");
 
88
    schema_message.set_collation("utf8_general_ci");
85
89
  }
86
90
  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
87
91
  {
88
 
    schema_message= data_dictionary_message;
 
92
    schema_message.set_name("data_dictionary");
 
93
    schema_message.set_collation("utf8_general_ci");
89
94
  }
90
95
  else
91
96
  {
92
 
    return drizzled::message::schema::shared_ptr();
 
97
    return false;
93
98
  }
94
99
 
95
 
  return schema_message;
 
100
  return true;
96
101
}
97
102
 
98
 
bool Function::doCanCreateTable(const drizzled::identifier::Table &table_identifier)
 
103
bool Function::doCanCreateTable(const drizzled::TableIdentifier &table_identifier)
99
104
{
100
 
  if (static_cast<const identifier::Schema&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
 
105
  if (static_cast<const SchemaIdentifier&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
101
106
  {
102
107
    return false;
103
108
  }
104
109
 
105
 
  else if (static_cast<const identifier::Schema&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
 
110
  else if (static_cast<const SchemaIdentifier&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
106
111
  {
107
112
    return false;
108
113
  }
110
115
  return true;
111
116
}
112
117
 
113
 
bool Function::doDoesTableExist(Session&, const identifier::Table &identifier)
 
118
bool Function::doDoesTableExist(Session&, const TableIdentifier &identifier)
114
119
{
115
120
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
116
121
 
122
127
 
123
128
 
124
129
void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
125
 
                                     const drizzled::identifier::Schema &schema_identifier,
126
 
                                     drizzled::identifier::Table::vector &set_of_identifiers)
 
130
                                     const drizzled::SchemaIdentifier &schema_identifier,
 
131
                                     drizzled::TableIdentifiers &set_of_identifiers)
127
132
{
128
 
  set<std::string> set_of_names;
 
133
  set<string> set_of_names;
129
134
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
130
135
 
131
 
  for (set<std::string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
 
136
  for (set<string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
132
137
  {
133
 
    set_of_identifiers.push_back(identifier::Table(schema_identifier, *iter, drizzled::message::Table::FUNCTION));
 
138
    set_of_identifiers.push_back(TableIdentifier(schema_identifier, *iter));
134
139
  }
135
140
}
136
141
 
150
155
  "Function Engine provides the infrastructure for Table Functions,etc.",
151
156
  PLUGIN_LICENSE_GPL,
152
157
  init,     /* Plugin Init */
153
 
  NULL,               /* depends */
 
158
  NULL,               /* system variables */
154
159
  NULL                /* config options   */
155
160
}
156
161
DRIZZLE_DECLARE_PLUGIN_END;