~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/info_schema/status.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
/**
22
 
 * @file 
23
 
 *   status I_S table methods.
24
 
 */
25
 
 
26
 
#include "config.h"
27
 
#include "drizzled/session.h"
28
 
#include "drizzled/show.h"
29
 
#include "drizzled/tztime.h"
30
 
#include "drizzled/pthread_globals.h"
31
 
 
32
 
#include "helper_methods.h"
33
 
#include "status.h"
34
 
 
35
 
#include <vector>
36
 
 
37
 
using namespace drizzled;
38
 
using namespace std;
39
 
 
40
 
/*
41
 
 * Vectors of columns for the status I_S tables.
42
 
 */
43
 
vector<const plugin::ColumnInfo *> *status_columns= NULL;
44
 
 
45
 
/*
46
 
 * Methods for the status related I_S tables.
47
 
 */
48
 
static plugin::InfoSchemaMethods *methods= NULL;
49
 
 
50
 
/*
51
 
 * status I_S tables.
52
 
 */
53
 
static plugin::InfoSchemaTable *glob_status_table= NULL;
54
 
static plugin::InfoSchemaTable *sess_status_table= NULL;
55
 
static plugin::InfoSchemaTable *status_table= NULL;
56
 
 
57
 
/**
58
 
 * Populate the vectors of columns for the I_S table.
59
 
 *
60
 
 * @return a pointer to a std::vector of Columns.
61
 
 */
62
 
vector<const plugin::ColumnInfo *> *GlobalStatusIS::createColumns()
63
 
{
64
 
  if (status_columns == NULL)
65
 
  {
66
 
    status_columns= new vector<const plugin::ColumnInfo *>;
67
 
  }
68
 
  else
69
 
  {
70
 
    clearColumns(*status_columns);
71
 
  }
72
 
 
73
 
  status_columns->push_back(new plugin::ColumnInfo("VARIABLE_NAME",
74
 
                                                   64,
75
 
                                                   DRIZZLE_TYPE_VARCHAR,
76
 
                                                   0,
77
 
                                                   0,
78
 
                                                   "Variable_name"));
79
 
 
80
 
  status_columns->push_back(new plugin::ColumnInfo("VARIABLE_VALUE",
81
 
                                                   16300,
82
 
                                                   DRIZZLE_TYPE_VARCHAR,
83
 
                                                   0,
84
 
                                                   1,
85
 
                                                   "Value"));
86
 
 
87
 
  return status_columns;
88
 
}
89
 
 
90
 
/**
91
 
 * Initialize the I_S table.
92
 
 *
93
 
 * @return a pointer to an I_S table
94
 
 */
95
 
plugin::InfoSchemaTable *GlobalStatusIS::getTable()
96
 
{
97
 
  status_columns= createColumns();
98
 
 
99
 
  if (methods == NULL)
100
 
  {
101
 
    methods= new StatusISMethods();
102
 
  }
103
 
 
104
 
  if (glob_status_table == NULL)
105
 
  {
106
 
    glob_status_table= new plugin::InfoSchemaTable("OLD_GLOBAL_STATUS",
107
 
                                                   *status_columns,
108
 
                                                   -1, -1, false, false,
109
 
                                                   0, 
110
 
                                                   methods);
111
 
  }
112
 
 
113
 
  return glob_status_table;
114
 
}
115
 
 
116
 
/**
117
 
 * Delete memory allocated for the table, columns and methods.
118
 
 */
119
 
void GlobalStatusIS::cleanup()
120
 
{
121
 
  clearColumns(*status_columns);
122
 
  delete glob_status_table;
123
 
  delete methods;
124
 
  delete status_columns;
125
 
}
126
 
 
127
 
/**
128
 
 * Initialize the I_S table.
129
 
 *
130
 
 * @return a pointer to an I_S table
131
 
 */
132
 
plugin::InfoSchemaTable *SessionStatusIS::getTable()
133
 
{
134
 
  if (sess_status_table == NULL)
135
 
  {
136
 
    sess_status_table= new plugin::InfoSchemaTable("OPEN_SESSION_STATUS",
137
 
                                                   *status_columns,
138
 
                                                   -1, -1, false, false,
139
 
                                                   0, 
140
 
                                                   methods);
141
 
  }
142
 
 
143
 
  return sess_status_table;
144
 
}
145
 
 
146
 
/**
147
 
 * Delete memory allocated for the table, columns and methods.
148
 
 */
149
 
void SessionStatusIS::cleanup()
150
 
{
151
 
  delete sess_status_table;
152
 
}
153
 
 
154
 
/**
155
 
 * Initialize the I_S table.
156
 
 *
157
 
 * @return a pointer to an I_S table
158
 
 */
159
 
plugin::InfoSchemaTable *StatusIS::getTable()
160
 
{
161
 
  if (status_table == NULL)
162
 
  {
163
 
    status_table= new plugin::InfoSchemaTable("OLD_STATUS",
164
 
                                              *status_columns,
165
 
                                              -1, -1, true, false, 0,
166
 
                                              methods);
167
 
  }
168
 
 
169
 
  return status_table;
170
 
}
171
 
 
172
 
/**
173
 
 * Delete memory allocated for the table, columns and methods.
174
 
 */
175
 
void StatusIS::cleanup()
176
 
{
177
 
  delete status_table;
178
 
}
179
 
 
180
 
int StatusISMethods::fillTable(Session *session, 
181
 
                               Table *table,
182
 
                               plugin::InfoSchemaTable *schema_table)
183
 
{
184
 
  LEX *lex= session->lex;
185
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
186
 
  int res= 0;
187
 
  STATUS_VAR *tmp1, tmp;
188
 
  const string schema_table_name= schema_table->getTableName();
189
 
  sql_var_t option_type;
190
 
 
191
 
  if (schema_table_name.compare("STATUS") == 0)
192
 
  {
193
 
    option_type= lex->option_type;
194
 
    if (option_type == OPT_GLOBAL)
195
 
    {
196
 
      tmp1= &tmp;
197
 
    }
198
 
    else
199
 
    {
200
 
      tmp1= session->initial_status_var;
201
 
    }
202
 
  }
203
 
  else if (schema_table_name.compare("GLOBAL_STATUS") == 0)
204
 
  {
205
 
    option_type= OPT_GLOBAL;
206
 
    tmp1= &tmp;
207
 
  }
208
 
  else
209
 
  {
210
 
    option_type= OPT_SESSION;
211
 
    tmp1= &session->status_var;
212
 
  }
213
 
 
214
 
  pthread_mutex_lock(&LOCK_status);
215
 
  if (option_type == OPT_GLOBAL)
216
 
  {
217
 
    calc_sum_of_all_status(&tmp);
218
 
  }
219
 
  res= show_status_array(session, wild,
220
 
                         getFrontOfStatusVars(),
221
 
                         option_type, tmp1, "", table,
222
 
                         false,
223
 
                         schema_table);
224
 
  pthread_mutex_unlock(&LOCK_status);
225
 
  return res;
226
 
}
227