~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/query_cache.cc

Merge Revision revid:marko.makela@oracle.com-20100514133144-fe0l0b89tea4x4uu from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100514133144-fe0l0b89tea4x4uu

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Merge from mysql-5.1-innodb:

Post-merge fixes: Remove the MYSQL_VERSION_ID checks, because they only
apply to the InnoDB Plugin. Fix potential race condition accessing
trx->op_info and trx->detailed_error.
------------------------------------------------------------
revno: 3466
revision-id: marko.makela@oracle.com-20100514130815-ym7j7cfu88ro6km4
parent: marko.makela@oracle.com-20100514130228-n3n42nw7ht78k0wn
committer: Marko Mkel <marko.makela@oracle.com>
branch nick: mysql-5.1-innodb2
timestamp: Fri 2010-05-14 16:08:15 +0300
message:
  Make the InnoDB FOREIGN KEY parser understand multi-statements. (Bug #48024)
  Also make InnoDB thinks that /*/ only starts a comment. (Bug #53644).

  This fixes the bugs in the InnoDB Plugin.

  ha_innodb.h: Use trx_query_string() instead of trx_query() when
  available (MySQL 5.1.42 or later).

  innobase_get_stmt(): New function, to retrieve the currently running
  SQL statement.

  struct trx_struct: Remove mysql_query_str. Use innobase_get_stmt() instead.

  dict_strip_comments(): Add and observe the parameter sql_length. Treat
  /*/ as the start of a comment.

  dict_create_foreign_constraints(), row_table_add_foreign_constraints():
  Add the parameter sql_length.

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) 2008 Mark Atwood
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *  Copyright (C) 2010 Djellel Eddine Difallah
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
7
8
 *  it under the terms of the GNU General Public License as published by
17
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19
 */
19
20
 
20
 
#include <drizzled/server_includes.h>
21
 
#include <drizzled/qcache.h>
22
 
#include <drizzled/gettext.h>
23
 
 
24
 
int qcache_initializer(st_plugin_int *plugin)
25
 
{
26
 
  qcache_t *p;
27
 
 
28
 
  p= (qcache_t *) malloc(sizeof(qcache_t));
29
 
  if (p == NULL) return 1;
30
 
  memset(p, 0, sizeof(qcache_t));
31
 
 
32
 
  plugin->data= (void *)p;
33
 
 
34
 
  if (plugin->plugin->init)
35
 
  {
36
 
    if (plugin->plugin->init((void *)p))
37
 
    {
38
 
      /* TRANSLATORS: The leading word "qcache" is the name
39
 
         of the plugin api, and so should not be translated. */
40
 
      sql_print_error(_("qcache plugin '%s' init() failed"),
41
 
                      plugin->name.str);
42
 
      goto err;
43
 
    }
44
 
  }
45
 
  return 0;
46
 
 
47
 
err:
48
 
  free(p);
49
 
  return 1;
50
 
}
51
 
 
52
 
int qcache_finalizer(st_plugin_int *plugin)
53
 
54
 
  qcache_t *p= (qcache_t *) plugin->data;
55
 
 
56
 
  if (plugin->plugin->deinit)
57
 
  {
58
 
    if (plugin->plugin->deinit((void *)p))
59
 
    {
60
 
      /* TRANSLATORS: The leading word "qcache" is the name
61
 
         of the plugin api, and so should not be translated. */
62
 
      sql_print_error(_("qcache plugin '%s' deinit() failed"),
63
 
                      plugin->name.str);
64
 
    }
65
 
  }
66
 
 
67
 
  if (p) free(p);
68
 
 
69
 
  return 0;
70
 
}
71
 
 
72
 
/* The plugin_foreach() iterator requires that we
73
 
   convert all the parameters of a plugin api entry point
74
 
   into just one single void ptr, plus the session.
75
 
   So we will take all the additional paramters of qcache_do1,
76
 
   and marshall them into a struct of this type, and
77
 
   then just pass in a pointer to it.
78
 
*/
79
 
typedef struct qcache_do1_parms_st
80
 
{
81
 
  void *parm1;
82
 
  void *parm2;
83
 
} qcache_do1_parms_t;
84
 
 
85
 
/* This gets called by plugin_foreach once for each loaded qcache plugin */
86
 
static bool qcache_do1_iterate (Session *session, plugin_ref plugin, void *p)
87
 
{
88
 
  qcache_t *l= plugin_data(plugin, qcache_t *);
89
 
  qcache_do1_parms_t *parms= (qcache_do1_parms_t *) p;
90
 
 
91
 
  /* call this loaded qcache plugin's qcache_func1 function pointer */
92
 
  if (l && l->qcache_func1)
93
 
  {
94
 
    if (l->qcache_func1(session, parms->parm1, parms->parm2))
95
 
    {
96
 
      /* TRANSLATORS: The leading word "qcache" is the name
97
 
         of the plugin api, and so should not be translated. */
98
 
      sql_print_error(_("qcache plugin '%s' do1() failed"),
99
 
                      (char *)plugin_name(plugin));
100
 
      return true;
101
 
    }
102
 
  }
103
 
  return false;
104
 
}
105
 
 
106
 
/* This is the qcache_do1 entry point.
107
 
   This gets called by the rest of the Drizzle server code */
108
 
bool qcache_do1 (Session *session, void *parm1, void *parm2)
109
 
{
110
 
  qcache_do1_parms_t parms;
111
 
  bool foreach_rv;
112
 
 
113
 
  /* marshall the parameters so they will fit into the foreach */
114
 
  parms.parm1= parm1;
115
 
  parms.parm2= parm2;
116
 
 
117
 
  /* call qcache_do1_iterate
118
 
     once for each loaded qcache plugin */
119
 
  foreach_rv= plugin_foreach(session,
120
 
                             qcache_do1_iterate,
121
 
                             DRIZZLE_QCACHE_PLUGIN,
122
 
                             (void *) &parms);
123
 
  return foreach_rv;
124
 
}
125
 
 
126
 
/* The plugin_foreach() iterator requires that we
127
 
   convert all the parameters of a plugin api entry point
128
 
   into just one single void ptr, plus the session.
129
 
   So we will take all the additional paramters of qcache_do2,
130
 
   and marshall them into a struct of this type, and
131
 
   then just pass in a pointer to it.
132
 
*/
133
 
typedef struct qcache_do2_parms_st
134
 
{
135
 
  void *parm3;
136
 
  void *parm4;
137
 
} qcache_do2_parms_t;
138
 
 
139
 
/* This gets called by plugin_foreach once for each loaded qcache plugin */
140
 
static bool qcache_do2_iterate (Session *session, plugin_ref plugin, void *p)
141
 
{
142
 
  qcache_t *l= plugin_data(plugin, qcache_t *);
143
 
  qcache_do2_parms_t *parms= (qcache_do2_parms_t *) p;
144
 
 
145
 
  /* call this loaded qcache plugin's qcache_func1 function pointer */
146
 
  if (l && l->qcache_func1)
147
 
  {
148
 
    if (l->qcache_func2(session, parms->parm3, parms->parm4))
149
 
    {
150
 
      /* TRANSLATORS: The leading word "qcache" is the name
151
 
         of the plugin api, and so should not be translated. */
152
 
      sql_print_error(_("qcache plugin '%s' qcache_func2() failed"),
153
 
                      (char *)plugin_name(plugin));
154
 
 
155
 
      return true;
156
 
    }
157
 
  }
158
 
  return false;
159
 
}
160
 
 
161
 
/* This is the qcache_do2 entry point.
162
 
   This gets called by the rest of the Drizzle server code */
163
 
bool qcache_do2 (Session *session, void *parm3, void *parm4)
164
 
{
165
 
  qcache_do2_parms_t parms;
166
 
  bool foreach_rv;
167
 
 
168
 
  /* marshall the parameters so they will fit into the foreach */
169
 
  parms.parm3= parm3;
170
 
  parms.parm4= parm4;
171
 
 
172
 
  /* call qcache_do2_iterate
173
 
     once for each loaded qcache plugin */
174
 
  foreach_rv= plugin_foreach(session,
175
 
                             qcache_do2_iterate,
176
 
                             DRIZZLE_QCACHE_PLUGIN,
177
 
                             (void *) &parms);
178
 
  return foreach_rv;
179
 
}
 
21
#include "config.h"
 
22
#include "drizzled/plugin/query_cache.h"
 
23
#include "drizzled/errmsg_print.h"
 
24
 
 
25
#include "drizzled/gettext.h"
 
26
 
 
27
#include <algorithm>
 
28
#include <vector>
 
29
 
 
30
class Session;
 
31
 
 
32
using namespace std;
 
33
 
 
34
namespace drizzled
 
35
{
 
36
typedef vector<plugin::QueryCache *> QueryCaches;
 
37
QueryCaches all_query_cache;
 
38
 
 
39
/* Namespaces are here to prevent global symbol clashes with these classes */
 
40
 
 
41
class IsCachedIterate
 
42
 : public unary_function<plugin::QueryCache *, bool>
 
43
{
 
44
  Session *session;
 
45
public:
 
46
  IsCachedIterate(Session* session_arg) :
 
47
    unary_function<plugin::QueryCache *, bool>(),
 
48
    session(session_arg) { }
 
49
 
 
50
  inline result_type operator()(argument_type handler)
 
51
  {
 
52
    return handler->doIsCached(session);
 
53
  }
 
54
};
 
55
 
 
56
bool plugin::QueryCache::isCached(Session *session)
 
57
{
 
58
  /* Use find_if instead of foreach so that we can collect return codes */
 
59
  QueryCaches::iterator iter=
 
60
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
61
            IsCachedIterate(session));
 
62
  /* If iter is == end() here, that means that all of the plugins returned
 
63
   * false, which in this case means they all succeeded. Since we want to 
 
64
   * return false on success, we return the value of the two being != 
 
65
   */
 
66
  return iter != all_query_cache.end();
 
67
}
 
68
 
 
69
 
 
70
class SendCachedResultsetIterate
 
71
 : public unary_function<plugin::QueryCache *, bool>
 
72
{
 
73
  Session *session;
 
74
public:
 
75
  SendCachedResultsetIterate(Session *session_arg) :
 
76
    unary_function<plugin::QueryCache *, bool>(),
 
77
    session(session_arg) { }
 
78
 
 
79
  inline result_type operator()(argument_type handler)
 
80
  {
 
81
    return handler->doSendCachedResultset(session);
 
82
  }
 
83
};
 
84
bool plugin::QueryCache::sendCachedResultset(Session *session)
 
85
{
 
86
  /* Use find_if instead of foreach so that we can collect return codes */
 
87
  QueryCaches::iterator iter=
 
88
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
89
            SendCachedResultsetIterate(session));
 
90
  /* If iter is == end() here, that means that all of the plugins returned
 
91
   * false, which in this case means they all succeeded. Since we want to 
 
92
   * return false on success, we return the value of the two being != 
 
93
   */
 
94
  return iter != all_query_cache.end();
 
95
}
 
96
 
 
97
class PrepareResultsetIterate
 
98
 : public unary_function<plugin::QueryCache *, bool>
 
99
{
 
100
  Session *session;
 
101
public:
 
102
  PrepareResultsetIterate(Session *session_arg) :
 
103
    unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
 
104
 
 
105
  inline result_type operator()(argument_type handler)
 
106
  {
 
107
    return handler->doPrepareResultset(session);
 
108
  }
 
109
};
 
110
bool plugin::QueryCache::prepareResultset(Session *session)
 
111
{
 
112
  /* Use find_if instead of foreach so that we can collect return codes */
 
113
  QueryCaches::iterator iter=
 
114
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
115
            PrepareResultsetIterate(session));
 
116
  /* If iter is == end() here, that means that all of the plugins returned
 
117
   * false, which in this case means they all succeeded. Since we want to 
 
118
   * return false on success, we return the value of the two being != 
 
119
   */
 
120
  return iter != all_query_cache.end();
 
121
}
 
122
 
 
123
class SetResultsetIterate
 
124
 : public unary_function<plugin::QueryCache *, bool>
 
125
{
 
126
  Session *session;
 
127
public:
 
128
  SetResultsetIterate(Session *session_arg) :
 
129
    unary_function<plugin::QueryCache *, bool>(),
 
130
    session(session_arg) { }
 
131
 
 
132
  inline result_type operator()(argument_type handler)
 
133
  {
 
134
    return handler->doSetResultset(session);
 
135
  }
 
136
};
 
137
 
 
138
bool plugin::QueryCache::setResultset(Session *session)
 
139
{
 
140
  /* Use find_if instead of foreach so that we can collect return codes */
 
141
  QueryCaches::iterator iter=
 
142
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
143
            SetResultsetIterate(session));
 
144
  /* If iter is == end() here, that means that all of the plugins returned
 
145
   * false, which in this case means they all succeeded. Since we want to 
 
146
   * return false on success, we return the value of the two being != 
 
147
   */
 
148
  return iter != all_query_cache.end();
 
149
}
 
150
 
 
151
class InsertRecordIterate
 
152
 : public unary_function<plugin::QueryCache *, bool>
 
153
{
 
154
  Session *session;
 
155
  List<Item> &item;
 
156
public:
 
157
  InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
 
158
    unary_function<plugin::QueryCache *, bool>(),
 
159
    session(session_arg), item(item_arg) { }
 
160
 
 
161
  inline result_type operator()(argument_type handler)
 
162
  {
 
163
    return handler->doInsertRecord(session, item);
 
164
  }
 
165
};
 
166
bool plugin::QueryCache::insertRecord(Session *session, List<Item> &items)
 
167
{
 
168
  /* Use find_if instead of foreach so that we can collect return codes */
 
169
  QueryCaches::iterator iter=
 
170
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
171
            InsertRecordIterate(session, items));
 
172
  /* If iter is == end() here, that means that all of the plugins returned
 
173
   * false, which in this case means they all succeeded. Since we want to 
 
174
   * return false on success, we return the value of the two being != 
 
175
   */
 
176
  return iter != all_query_cache.end();
 
177
}
 
178
 
 
179
 
 
180
 
 
181
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
 
182
{
 
183
  all_query_cache.push_back(handler);
 
184
  return false;
 
185
}
 
186
 
 
187
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
 
188
{
 
189
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
 
190
                        handler));
 
191
}
 
192
 
 
193
} /* namespace drizzled */