492.3.24
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 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; 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
|
|
18 |
*/
|
|
19 |
||
20 |
#include <drizzled/server_includes.h> |
|
21 |
#include CSTDINT_H
|
|
670.1.20
by Monty Taylor
Renamed functions to function... everything else is singular. |
22 |
#include <drizzled/function/benchmark.h> |
492.3.27
by Lee
merge latest changes from the trunk and changes to get drizzle building on Soalris 10 (SPARC) |
23 |
#include <drizzled/error.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
24 |
#include <drizzled/session.h> |
492.3.27
by Lee
merge latest changes from the trunk and changes to get drizzle building on Soalris 10 (SPARC) |
25 |
|
492.3.24
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
26 |
|
27 |
/* This function is just used to test speed of different functions */
|
|
28 |
||
29 |
int64_t Item_func_benchmark::val_int() |
|
30 |
{
|
|
31 |
assert(fixed == 1); |
|
32 |
char buff[MAX_FIELD_WIDTH]; |
|
33 |
String tmp(buff,sizeof(buff), &my_charset_bin); |
|
34 |
my_decimal tmp_decimal; |
|
35 |
Session *session=current_session; |
|
36 |
uint64_t loop_count; |
|
37 |
||
38 |
loop_count= (uint64_t) args[0]->val_int(); |
|
39 |
||
40 |
if (args[0]->null_value || |
|
41 |
(!args[0]->unsigned_flag && (((int64_t) loop_count) < 0))) |
|
42 |
{
|
|
43 |
if (!args[0]->null_value) |
|
44 |
{
|
|
45 |
char buff[22]; |
|
46 |
llstr(((int64_t) loop_count), buff); |
|
47 |
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
|
48 |
ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE), |
|
49 |
"count", buff, "benchmark"); |
|
50 |
}
|
|
51 |
||
52 |
null_value= 1; |
|
53 |
return 0; |
|
54 |
}
|
|
55 |
||
56 |
null_value=0; |
|
57 |
for (uint64_t loop=0 ; loop < loop_count && !session->killed; loop++) |
|
58 |
{
|
|
59 |
switch (args[1]->result_type()) { |
|
60 |
case REAL_RESULT: |
|
61 |
(void) args[1]->val_real(); |
|
62 |
break; |
|
63 |
case INT_RESULT: |
|
64 |
(void) args[1]->val_int(); |
|
65 |
break; |
|
66 |
case STRING_RESULT: |
|
67 |
(void) args[1]->val_str(&tmp); |
|
68 |
break; |
|
69 |
case DECIMAL_RESULT: |
|
70 |
(void) args[1]->val_decimal(&tmp_decimal); |
|
71 |
break; |
|
72 |
case ROW_RESULT: |
|
73 |
default: |
|
74 |
// This case should never be chosen
|
|
75 |
assert(0); |
|
76 |
return 0; |
|
77 |
}
|
|
78 |
}
|
|
79 |
return 0; |
|
80 |
}
|
|
81 |
||
82 |
||
83 |
void Item_func_benchmark::print(String *str, enum_query_type query_type) |
|
84 |
{
|
|
85 |
str->append(STRING_WITH_LEN("benchmark(")); |
|
86 |
args[0]->print(str, query_type); |
|
87 |
str->append(','); |
|
88 |
args[1]->print(str, query_type); |
|
89 |
str->append(')'); |
|
90 |
}
|
|
91 |