~drizzle-trunk/drizzle/development

1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
3
 *
4
 * Copyright (C) 2008 MySQL AB
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; version 2 of the License.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
18
 */
19
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
21
#include <drizzled/error.h>
2154.2.24 by Brian Aker
Merge in all changes for current_session, etc.
22
#include <drizzled/internal/m_string.h>
2198.1.2 by Olaf van der Spek
Refactor includes
23
#include <drizzled/plugin/function.h>
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
24
#include <drizzled/session.h>
25
26
using namespace std;
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
27
using namespace drizzled;
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
28
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
29
class BenchmarkFunction :public Item_int_func
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
30
{
31
public:
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
32
  BenchmarkFunction() :Item_int_func() {}
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
33
  int64_t val_int();
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
34
  virtual void print(String *str);
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
35
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
36
  const char *func_name() const
37
  { 
1030.3.8 by devananda
formatting cleanup
38
    return "benchmark"; 
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
39
  }
40
41
  void fix_length_and_dec()
42
  { 
1030.3.8 by devananda
formatting cleanup
43
    max_length= 1; 
44
    maybe_null= false;
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
45
  }
46
47
  bool check_argument_count(int n)
48
  { 
1030.3.8 by devananda
formatting cleanup
49
    return (n == 2); 
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
50
  }
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
51
};
52
53
54
/* This function is just used to test speed of different functions */
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
55
int64_t BenchmarkFunction::val_int()
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
56
{
1030.3.8 by devananda
formatting cleanup
57
  assert(fixed == true);
58
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
59
  char buff[MAX_FIELD_WIDTH];
60
  String tmp(buff,sizeof(buff), &my_charset_bin);
2030.1.4 by Brian Aker
Change my_decimal to Decimal
61
  type::Decimal tmp_decimal;
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
62
  uint64_t loop_count;
63
64
  loop_count= (uint64_t) args[0]->val_int();
65
66
  if (args[0]->null_value ||
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
67
      (args[0]->unsigned_flag == false && (((int64_t) loop_count) < 0)))
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
68
  {
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
69
    if (args[0]->null_value == false)
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
70
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
71
      internal::int64_t10_to_str((int64_t)loop_count, buff, -10);
2154.2.24 by Brian Aker
Merge in all changes for current_session, etc.
72
      push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
73
                          ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
74
                          "count", buff, "benchmark");
75
    }
76
1030.3.8 by devananda
formatting cleanup
77
    null_value= true;
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
78
    return 0;
79
  }
80
1030.3.8 by devananda
formatting cleanup
81
  null_value= false;
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
82
83
  uint64_t loop;
2154.2.24 by Brian Aker
Merge in all changes for current_session, etc.
84
  for (loop= 0 ; loop < loop_count && not getSession().getKilled(); loop++)
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
85
  {
1030.3.7 by devananda
applied comments from Jay&Stewart reviews: added de-init func, renamed from Item_func_benchmark to BenchmarkFunction, misc other cleanup
86
    switch (args[1]->result_type()) 
87
    {
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
88
    case REAL_RESULT:
89
      (void) args[1]->val_real();
90
      break;
91
    case INT_RESULT:
92
      (void) args[1]->val_int();
93
      break;
94
    case STRING_RESULT:
95
      (void) args[1]->val_str(&tmp);
96
      break;
97
    case DECIMAL_RESULT:
98
      (void) args[1]->val_decimal(&tmp_decimal);
99
      break;
100
    case ROW_RESULT:
101
    default:
102
      // This case should never be chosen
103
      assert(0);
104
      return 0;
105
    }
106
  }
107
  return 0;
108
}
109
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
110
void BenchmarkFunction::print(String *str)
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
111
{
112
  str->append(STRING_WITH_LEN("benchmark("));
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
113
  args[0]->print(str);
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
114
  str->append(',');
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
115
  args[1]->print(str);
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
116
  str->append(')');
117
}
118
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
119
plugin::Create_function<BenchmarkFunction> *benchmarkudf= NULL;
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
120
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
121
static int initialize(module::Context &context)
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
122
{
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
123
  benchmarkudf= new plugin::Create_function<BenchmarkFunction>("benchmark");
1324.2.2 by Monty Taylor
Use the plugin::Context everywhere.
124
  context.add(benchmarkudf);
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
125
  return 0;
126
}
127
1228.1.5 by Monty Taylor
Merged in some naming things.
128
DRIZZLE_DECLARE_PLUGIN
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
129
{
1241.10.2 by Monty Taylor
Added support for embedding the drizzle version number in the plugin file.
130
  DRIZZLE_VERSION_ID,
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
131
  "benchmark",
1030.3.8 by devananda
formatting cleanup
132
  "1.0",
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
133
  "Devananda van der Veen",
134
  "Measure time for repeated calls to a function.",
135
  PLUGIN_LICENSE_GPL,
136
  initialize, /* Plugin Init */
2095.3.1 by Monty Taylor
Re-purpose the old plugin sysvar slot in the struct to be a depends list.
137
  NULL,   /* depends */
1030.3.5 by devananda
refactored function/benchmark into plugin/benchmark
138
  NULL    /* config options */
139
}
1228.1.5 by Monty Taylor
Merged in some naming things.
140
DRIZZLE_DECLARE_PLUGIN_END;