summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/gen_lex_hash.cc8
-rw-r--r--sql/item_create.cc9
-rw-r--r--sql/item_create.h3
-rw-r--r--sql/item_func.cc31
-rw-r--r--sql/item_func.h20
-rw-r--r--sql/lex.h4
-rw-r--r--sql/sql_yacc.yy5
7 files changed, 71 insertions, 9 deletions
diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc
index 776b6840b45..c61a75ab880 100644
--- a/sql/gen_lex_hash.cc
+++ b/sql/gen_lex_hash.cc
@@ -74,13 +74,13 @@ static struct my_option my_long_options[] =
{"version", 'V', "Output version information and exit",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"rnd1", 'r', "Set 1 part of rnd value for hash generator",
- (gptr*) &best_t1, (gptr*) &best_t1, 0, GET_ULONG, REQUIRED_ARG, 6657025L,
+ (gptr*) &best_t1, (gptr*) &best_t1, 0, GET_ULONG, REQUIRED_ARG, 5075635L,
0, 0, 0, 0, 0},
{"rnd2", 'R', "Set 2 part of rnd value for hash generator",
- (gptr*) &best_t2, (gptr*) &best_t2, 0, GET_ULONG, REQUIRED_ARG, 6114496L,
+ (gptr*) &best_t2, (gptr*) &best_t2, 0, GET_ULONG, REQUIRED_ARG, 1345933L,
0, 0, 0, 0, 0},
{"type", 't', "Set type of char table to generate",
- (gptr*) &best_type, (gptr*) &best_type, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0,
+ (gptr*) &best_type, (gptr*) &best_type, 0, GET_UINT, REQUIRED_ARG, 4, 0, 0,
0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -479,7 +479,7 @@ int main(int argc,char **argv)
MY_INIT(argv[0]);
- start_value=1109118L; /* mode=4903 add=3 type: 0 */
+ start_value=3807640L; /* mode=6971 add=3 type: 0 */
if (get_options(argc,(char **) argv))
exit(1);
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 62f09f002d1..e75c7049a74 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -220,9 +220,14 @@ Item *create_func_char_length(Item* a)
return new Item_func_char_length(a);
}
-Item *create_func_log(Item* a)
+Item *create_func_ln(Item* a)
{
- return new Item_func_log(a);
+ return new Item_func_ln(a);
+}
+
+Item *create_func_log2(Item* a)
+{
+ return new Item_func_log2(a);
}
Item *create_func_log10(Item* a)
diff --git a/sql/item_create.h b/sql/item_create.h
index 967de0e2eba..730a1510988 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -52,8 +52,9 @@ Item *create_func_instr(Item* a, Item *b);
Item *create_func_isnull(Item* a);
Item *create_func_lcase(Item* a);
Item *create_func_length(Item* a);
+Item *create_func_ln(Item* a);
Item *create_func_locate(Item* a, Item *b);
-Item *create_func_log(Item* a);
+Item *create_func_log2(Item* a);
Item *create_func_log10(Item* a);
Item *create_func_lpad(Item* a, Item *b, Item *c);
Item *create_func_ltrim(Item* a);
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 4ec4377509f..807f023b308 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -437,14 +437,43 @@ void Item_func_abs::fix_length_and_dec()
hybrid_type= args[0]->result_type() == INT_RESULT ? INT_RESULT : REAL_RESULT;
}
+/* Gateway to natural LOG function */
+double Item_func_ln::val()
+{
+ double value=args[0]->val();
+ if ((null_value=(args[0]->null_value || value <= 0.0)))
+ return 0.0;
+ return log(value);
+}
+
+/*
+ Extended but so slower LOG function
+ We have to check if all values are > zero and first one is not one
+ as these are the cases then result is not a number.
+*/
double Item_func_log::val()
{
double value=args[0]->val();
if ((null_value=(args[0]->null_value || value <= 0.0)))
- return 0.0; /* purecov: inspected */
+ return 0.0;
+ if (arg_count == 2)
+ {
+ double value2= args[1]->val();
+ if ((null_value=(args[1]->null_value || value2 <= 0.0 || value == 1.0)))
+ return 0.0;
+ return log(value2) / log(value);
+ }
return log(value);
}
+double Item_func_log2::val()
+{
+ double value=args[0]->val();
+ if ((null_value=(args[0]->null_value || value <= 0.0)))
+ return 0.0;
+ return log(value) / log(2.0);
+}
+
double Item_func_log10::val()
{
double value=args[0]->val();
diff --git a/sql/item_func.h b/sql/item_func.h
index 5560d3cdb0d..0860e15d2e4 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -338,15 +338,35 @@ public:
const char *func_name() const { return "exp"; }
};
+
+class Item_func_ln :public Item_dec_func
+{
+public:
+ Item_func_ln(Item *a) :Item_dec_func(a) {}
+ double val();
+ const char *func_name() const { return "ln"; }
+};
+
+
class Item_func_log :public Item_dec_func
{
public:
Item_func_log(Item *a) :Item_dec_func(a) {}
+ Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {}
double val();
const char *func_name() const { return "log"; }
};
+class Item_func_log2 :public Item_dec_func
+{
+public:
+ Item_func_log2(Item *a) :Item_dec_func(a) {}
+ double val();
+ const char *func_name() const { return "log2"; }
+};
+
+
class Item_func_log10 :public Item_dec_func
{
public:
diff --git a/sql/lex.h b/sql/lex.h
index 81d597c6a5c..5a5e539a25b 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -461,9 +461,11 @@ static SYMBOL sql_functions[] = {
{ "LCASE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_lcase)},
{ "LEAST", SYM(LEAST_SYM),0,0},
{ "LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_length)},
+ { "LN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ln)},
{ "LOAD_FILE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_load_file)},
{ "LOCATE", SYM(LOCATE),0,0},
- { "LOG", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_log)},
+ { "LOG", SYM(LOG_SYM),0,0},
+ { "LOG2", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_log2)},
{ "LOG10", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_log10)},
{ "LOWER", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_lcase)},
{ "LPAD", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_lpad)},
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 6a4f13940a7..af094997341 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -231,6 +231,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token LIKE
%token LINES
%token LOCAL_SYM
+%token LOG_SYM
%token LOGS_SYM
%token LONG_NUM
%token LONG_SYM
@@ -1779,6 +1780,10 @@ simple_expr:
{ $5->push_front($3); $$= new Item_func_max(*$5); }
| LEAST_SYM '(' expr ',' expr_list ')'
{ $5->push_front($3); $$= new Item_func_min(*$5); }
+ | LOG_SYM '(' expr ')'
+ { $$= new Item_func_log($3); }
+ | LOG_SYM '(' expr ',' expr ')'
+ { $$= new Item_func_log($3, $5); }
| MINUTE_SYM '(' expr ')'
{ $$= new Item_func_minute($3); }
| MONTH_SYM '(' expr ')'