2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2000-2003, 2005 MySQL AB
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
|
|
|
|
/* Analyse database */
|
|
|
|
|
2005-05-26 12:09:14 +02:00
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
2000-07-31 21:29:14 +02:00
|
|
|
#pragma interface /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
2003-03-07 09:21:32 +01:00
|
|
|
#define my_thd_charset default_charset_info
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
#define DEC_IN_AVG 4
|
|
|
|
|
|
|
|
typedef struct st_number_info
|
|
|
|
{
|
|
|
|
// if zerofill is true, the number must be zerofill, or string
|
|
|
|
bool negative, is_float, zerofill, maybe_zerofill;
|
|
|
|
int8 integers;
|
|
|
|
int8 decimals;
|
|
|
|
double dval;
|
|
|
|
ulonglong ullval;
|
|
|
|
} NUM_INFO;
|
|
|
|
|
|
|
|
typedef struct st_extreme_value_number_info
|
|
|
|
{
|
|
|
|
ulonglong ullval;
|
|
|
|
longlong llval;
|
|
|
|
double max_dval, min_dval;
|
|
|
|
} EV_NUM_INFO;
|
|
|
|
|
|
|
|
typedef struct st_tree_info
|
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
String *str;
|
|
|
|
Item *item;
|
|
|
|
} TREE_INFO;
|
|
|
|
|
|
|
|
uint check_ulonglong(const char *str, uint length);
|
|
|
|
bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num);
|
2000-08-21 23:18:32 +02:00
|
|
|
bool test_if_number(NUM_INFO *info, const char *str, uint str_len);
|
2000-07-31 21:29:14 +02:00
|
|
|
int compare_double(const double *s, const double *t);
|
2001-05-11 02:14:15 +02:00
|
|
|
int compare_double2(void* cmp_arg __attribute__((unused)),
|
|
|
|
const double *s, const double *t);
|
2000-07-31 21:29:14 +02:00
|
|
|
int compare_longlong(const longlong *s, const longlong *t);
|
2001-05-11 02:14:15 +02:00
|
|
|
int compare_longlong2(void* cmp_arg __attribute__((unused)),
|
|
|
|
const longlong *s, const longlong *t);
|
2000-07-31 21:29:14 +02:00
|
|
|
int compare_ulonglong(const ulonglong *s, const ulonglong *t);
|
2001-05-11 02:14:15 +02:00
|
|
|
int compare_ulonglong2(void* cmp_arg __attribute__((unused)),
|
|
|
|
const ulonglong *s, const ulonglong *t);
|
2005-02-08 23:50:45 +01:00
|
|
|
int compare_decimal2(int* len, const char *s, const char *t);
|
2000-07-31 21:29:14 +02:00
|
|
|
Procedure *proc_analyse_init(THD *thd, ORDER *param, select_result *result,
|
|
|
|
List<Item> &field_list);
|
|
|
|
void free_string(String*);
|
|
|
|
class analyse;
|
|
|
|
|
|
|
|
class field_info :public Sql_alloc
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
ulong treemem, tree_elements, empty, nulls, min_length, max_length;
|
|
|
|
uint room_in_tree;
|
|
|
|
my_bool found;
|
|
|
|
TREE tree;
|
|
|
|
Item *item;
|
|
|
|
analyse *pc;
|
|
|
|
|
|
|
|
public:
|
|
|
|
field_info(Item* a, analyse* b) : treemem(0), tree_elements(0), empty(0),
|
|
|
|
nulls(0), min_length(0), max_length(0), room_in_tree(1),
|
|
|
|
found(0),item(a), pc(b) {};
|
|
|
|
|
|
|
|
virtual ~field_info() { delete_tree(&tree); }
|
|
|
|
virtual void add() = 0;
|
|
|
|
virtual void get_opt_type(String*, ha_rows) = 0;
|
|
|
|
virtual String *get_min_arg(String *) = 0;
|
|
|
|
virtual String *get_max_arg(String *) = 0;
|
|
|
|
virtual String *avg(String*, ha_rows) = 0;
|
|
|
|
virtual String *std(String*, ha_rows) = 0;
|
|
|
|
virtual tree_walk_action collect_enum() = 0;
|
|
|
|
virtual uint decimals() { return 0; }
|
|
|
|
friend class analyse;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-01-27 00:20:56 +01:00
|
|
|
int collect_string(String *element, element_count count,
|
|
|
|
TREE_INFO *info);
|
|
|
|
|
2001-05-11 02:14:15 +02:00
|
|
|
int sortcmp2(void* cmp_arg __attribute__((unused)),
|
|
|
|
const String *a,const String *b);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
class field_str :public field_info
|
|
|
|
{
|
|
|
|
String min_arg, max_arg;
|
|
|
|
ulonglong sum;
|
|
|
|
bool must_be_blob, was_zero_fill, was_maybe_zerofill,
|
|
|
|
can_be_still_num;
|
|
|
|
NUM_INFO num_info;
|
|
|
|
EV_NUM_INFO ev_num_info;
|
|
|
|
|
|
|
|
public:
|
2002-05-17 13:29:52 +02:00
|
|
|
field_str(Item* a, analyse* b) :field_info(a,b),
|
|
|
|
min_arg("",default_charset_info),
|
|
|
|
max_arg("",default_charset_info), sum(0),
|
2000-07-31 21:29:14 +02:00
|
|
|
must_be_blob(0), was_zero_fill(0),
|
|
|
|
was_maybe_zerofill(0), can_be_still_num(1)
|
2003-07-02 15:34:43 +02:00
|
|
|
{ init_tree(&tree, 0, 0, sizeof(String), (qsort_cmp2) sortcmp2,
|
2001-07-02 21:18:57 +02:00
|
|
|
0, (tree_element_free) free_string, NULL); };
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
void add();
|
|
|
|
void get_opt_type(String*, ha_rows);
|
|
|
|
String *get_min_arg(String *not_used __attribute__((unused)))
|
|
|
|
{ return &min_arg; }
|
|
|
|
String *get_max_arg(String *not_used __attribute__((unused)))
|
|
|
|
{ return &max_arg; }
|
|
|
|
String *avg(String *s, ha_rows rows)
|
|
|
|
{
|
|
|
|
if (!(rows - nulls))
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((double) 0.0, 1,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((ulonglong2double(sum) / ulonglong2double(rows - nulls)),
|
2002-10-30 13:19:43 +01:00
|
|
|
DEC_IN_AVG,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
friend int collect_string(String *element, element_count count,
|
|
|
|
TREE_INFO *info);
|
|
|
|
tree_walk_action collect_enum()
|
|
|
|
{ return (tree_walk_action) collect_string; }
|
|
|
|
String *std(String *s __attribute__((unused)),
|
|
|
|
ha_rows rows __attribute__((unused)))
|
|
|
|
{ return (String*) 0; }
|
|
|
|
};
|
|
|
|
|
2001-01-27 00:20:56 +01:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
int collect_decimal(uchar *element, element_count count,
|
2005-02-08 23:50:45 +01:00
|
|
|
TREE_INFO *info);
|
|
|
|
|
|
|
|
class field_decimal :public field_info
|
|
|
|
{
|
|
|
|
my_decimal min_arg, max_arg;
|
|
|
|
my_decimal sum[2], sum_sqr[2];
|
|
|
|
int cur_sum;
|
|
|
|
int bin_size;
|
|
|
|
public:
|
|
|
|
field_decimal(Item* a, analyse* b) :field_info(a,b)
|
|
|
|
{
|
|
|
|
bin_size= my_decimal_get_binary_size(a->max_length, a->decimals);
|
|
|
|
init_tree(&tree, 0, 0, bin_size, (qsort_cmp2)compare_decimal2,
|
|
|
|
0, 0, (void *)&bin_size);
|
|
|
|
};
|
|
|
|
|
|
|
|
void add();
|
|
|
|
void get_opt_type(String*, ha_rows);
|
|
|
|
String *get_min_arg(String *);
|
|
|
|
String *get_max_arg(String *);
|
|
|
|
String *avg(String *s, ha_rows rows);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
friend int collect_decimal(uchar *element, element_count count,
|
2005-02-08 23:50:45 +01:00
|
|
|
TREE_INFO *info);
|
|
|
|
tree_walk_action collect_enum()
|
|
|
|
{ return (tree_walk_action) collect_decimal; }
|
|
|
|
String *std(String *s, ha_rows rows);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-01-27 00:20:56 +01:00
|
|
|
int collect_real(double *element, element_count count, TREE_INFO *info);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
class field_real: public field_info
|
|
|
|
{
|
|
|
|
double min_arg, max_arg;
|
|
|
|
double sum, sum_sqr;
|
|
|
|
uint max_notzero_dec_len;
|
|
|
|
|
|
|
|
public:
|
|
|
|
field_real(Item* a, analyse* b) :field_info(a,b),
|
|
|
|
min_arg(0), max_arg(0), sum(0), sum_sqr(0), max_notzero_dec_len(0)
|
2001-07-02 21:18:57 +02:00
|
|
|
{ init_tree(&tree, 0, 0, sizeof(double),
|
|
|
|
(qsort_cmp2) compare_double2, 0, NULL, NULL); }
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
void add();
|
|
|
|
void get_opt_type(String*, ha_rows);
|
2006-06-16 12:17:20 +02:00
|
|
|
String *get_min_arg(String *s)
|
|
|
|
{
|
|
|
|
s->set_real(min_arg, item->decimals, my_thd_charset);
|
|
|
|
return s;
|
2002-10-30 13:19:43 +01:00
|
|
|
}
|
2006-06-16 12:17:20 +02:00
|
|
|
String *get_max_arg(String *s)
|
|
|
|
{
|
|
|
|
s->set_real(max_arg, item->decimals, my_thd_charset);
|
|
|
|
return s;
|
2002-10-30 13:19:43 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
String *avg(String *s, ha_rows rows)
|
|
|
|
{
|
|
|
|
if (!(rows - nulls))
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((double) 0.0, 1,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real(((double)sum / (double) (rows - nulls)), item->decimals,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
String *std(String *s, ha_rows rows)
|
|
|
|
{
|
|
|
|
double tmp = ulonglong2double(rows);
|
|
|
|
if (!(tmp - nulls))
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((double) 0.0, 1,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
double tmp2 = ((sum_sqr - sum * sum / (tmp - nulls)) /
|
|
|
|
(tmp - nulls));
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), item->decimals,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
uint decimals() { return item->decimals; }
|
|
|
|
friend int collect_real(double *element, element_count count,
|
|
|
|
TREE_INFO *info);
|
|
|
|
tree_walk_action collect_enum()
|
|
|
|
{ return (tree_walk_action) collect_real;}
|
|
|
|
};
|
|
|
|
|
2001-01-27 00:20:56 +01:00
|
|
|
int collect_longlong(longlong *element, element_count count,
|
|
|
|
TREE_INFO *info);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
class field_longlong: public field_info
|
|
|
|
{
|
|
|
|
longlong min_arg, max_arg;
|
|
|
|
longlong sum, sum_sqr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
field_longlong(Item* a, analyse* b) :field_info(a,b),
|
|
|
|
min_arg(0), max_arg(0), sum(0), sum_sqr(0)
|
2001-07-02 21:18:57 +02:00
|
|
|
{ init_tree(&tree, 0, 0, sizeof(longlong),
|
|
|
|
(qsort_cmp2) compare_longlong2, 0, NULL, NULL); }
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
void add();
|
|
|
|
void get_opt_type(String*, ha_rows);
|
2002-10-30 13:19:43 +01:00
|
|
|
String *get_min_arg(String *s) { s->set(min_arg,my_thd_charset); return s; }
|
|
|
|
String *get_max_arg(String *s) { s->set(max_arg,my_thd_charset); return s; }
|
2000-07-31 21:29:14 +02:00
|
|
|
String *avg(String *s, ha_rows rows)
|
|
|
|
{
|
|
|
|
if (!(rows - nulls))
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((double) 0.0, 1,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real(((double) sum / (double) (rows - nulls)), DEC_IN_AVG,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
String *std(String *s, ha_rows rows)
|
|
|
|
{
|
|
|
|
double tmp = ulonglong2double(rows);
|
|
|
|
if (!(tmp - nulls))
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((double) 0.0, 1,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
double tmp2 = ((sum_sqr - sum * sum / (tmp - nulls)) /
|
|
|
|
(tmp - nulls));
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), DEC_IN_AVG,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
friend int collect_longlong(longlong *element, element_count count,
|
|
|
|
TREE_INFO *info);
|
|
|
|
tree_walk_action collect_enum()
|
|
|
|
{ return (tree_walk_action) collect_longlong;}
|
|
|
|
};
|
|
|
|
|
2001-01-27 00:20:56 +01:00
|
|
|
int collect_ulonglong(ulonglong *element, element_count count,
|
|
|
|
TREE_INFO *info);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
class field_ulonglong: public field_info
|
|
|
|
{
|
|
|
|
ulonglong min_arg, max_arg;
|
|
|
|
ulonglong sum, sum_sqr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
field_ulonglong(Item* a, analyse * b) :field_info(a,b),
|
|
|
|
min_arg(0), max_arg(0), sum(0),sum_sqr(0)
|
2001-07-02 21:18:57 +02:00
|
|
|
{ init_tree(&tree, 0, 0, sizeof(ulonglong),
|
|
|
|
(qsort_cmp2) compare_ulonglong2, 0, NULL, NULL); }
|
2000-07-31 21:29:14 +02:00
|
|
|
void add();
|
|
|
|
void get_opt_type(String*, ha_rows);
|
2002-10-30 13:19:43 +01:00
|
|
|
String *get_min_arg(String *s) { s->set(min_arg,my_thd_charset); return s; }
|
|
|
|
String *get_max_arg(String *s) { s->set(max_arg,my_thd_charset); return s; }
|
2000-07-31 21:29:14 +02:00
|
|
|
String *avg(String *s, ha_rows rows)
|
|
|
|
{
|
|
|
|
if (!(rows - nulls))
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((double) 0.0, 1,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((ulonglong2double(sum) / ulonglong2double(rows - nulls)),
|
2002-10-30 13:19:43 +01:00
|
|
|
DEC_IN_AVG,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
String *std(String *s, ha_rows rows)
|
|
|
|
{
|
|
|
|
double tmp = ulonglong2double(rows);
|
|
|
|
if (!(tmp - nulls))
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real((double) 0.0, 1,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
double tmp2 = ((ulonglong2double(sum_sqr) -
|
|
|
|
ulonglong2double(sum * sum) / (tmp - nulls)) /
|
|
|
|
(tmp - nulls));
|
2006-06-16 12:17:20 +02:00
|
|
|
s->set_real(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), DEC_IN_AVG,my_thd_charset);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
friend int collect_ulonglong(ulonglong *element, element_count count,
|
|
|
|
TREE_INFO *info);
|
|
|
|
tree_walk_action collect_enum()
|
|
|
|
{ return (tree_walk_action) collect_ulonglong; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-01-27 00:20:56 +01:00
|
|
|
Procedure *proc_analyse_init(THD *thd, ORDER *param,
|
|
|
|
select_result *result,
|
|
|
|
List<Item> &field_list);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
class analyse: public Procedure
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
Item_proc *func_items[10];
|
|
|
|
List<Item> fields, result_fields;
|
|
|
|
field_info **f_info, **f_end;
|
|
|
|
ha_rows rows;
|
|
|
|
uint output_str_length;
|
|
|
|
|
|
|
|
public:
|
|
|
|
uint max_tree_elements, max_treemem;
|
|
|
|
|
2003-02-16 19:37:51 +01:00
|
|
|
analyse(select_result *res) :Procedure(res, PROC_NO_SORT), f_info(0),
|
|
|
|
rows(0), output_str_length(0) {}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
~analyse()
|
2003-02-16 19:37:51 +01:00
|
|
|
{
|
|
|
|
if (f_info)
|
2003-02-25 10:05:07 +01:00
|
|
|
{
|
2003-02-16 19:37:51 +01:00
|
|
|
for (field_info **f=f_info; f != f_end; f++)
|
|
|
|
delete (*f);
|
2003-02-25 10:05:07 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
virtual void add() {}
|
|
|
|
virtual bool change_columns(List<Item> &fields);
|
2007-08-15 15:43:08 +02:00
|
|
|
virtual int send_row(List<Item> &field_list);
|
2000-07-31 21:29:14 +02:00
|
|
|
virtual void end_group(void) {}
|
|
|
|
virtual bool end_of_records(void);
|
|
|
|
friend Procedure *proc_analyse_init(THD *thd, ORDER *param,
|
|
|
|
select_result *result,
|
|
|
|
List<Item> &field_list);
|
|
|
|
};
|