Commit 72f44daf authored by unknown's avatar unknown

NEWDATE -> DATE in anylyse() output

Changed that analyse(#) also affects strings


mysql-test/r/analyse.result:
  Better analyse test
mysql-test/t/analyse.test:
  Better analyse test
sql/sql_analyse.cc:
  NEWDATE -> DATE in anylyse() output
  Changed that analyse(#) also affects strings
  Fixed that number of elements in ENUM is limited by # not by #+1
parent d69a5630
Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
t1.i 1 7 1 1 0 0 4.0000 2.2361 ENUM('1','3','5','7') NOT NULL t1.i 1 7 1 1 0 0 4.0000 2.2361 ENUM('1','3','5','7') NOT NULL
t1.j 2 8 1 1 0 0 5.0000 2.2361 ENUM('2','4','6','8') NOT NULL t1.j 2 8 1 1 0 0 5.0000 2.2361 ENUM('2','4','6','8') NOT NULL
t1.empty_string 0 0 4 0 0.0000 NULL ENUM('') NOT NULL
t1.bool N Y 1 1 0 0 1.0000 NULL ENUM('N','Y') NOT NULL
t1.d 2002-03-04 10 10 0 0 10.0000 NULL ENUM('2002-03-03','2002-03-04','2002-03-05') NOT NULL
Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
t1.i 1 7 1 1 0 0 4.0000 2.2361 TINYINT(1) UNSIGNED NOT NULL
t1.j 2 8 1 1 0 0 5.0000 2.2361 TINYINT(1) UNSIGNED NOT NULL
t1.empty_string 0 0 4 0 0.0000 NULL CHAR(0) NOT NULL
t1.bool N Y 1 1 0 0 1.0000 NULL ENUM('N','Y') NOT NULL
t1.d 2002-03-04 10 10 0 0 10.0000 NULL DATE NOT NULL
Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
t1.i 1 7 1 1 0 0 4.0000 2.2361 ENUM('1','3','5','7') NOT NULL t1.i 1 7 1 1 0 0 4.0000 2.2361 ENUM('1','3','5','7') NOT NULL
t1.j 2 8 1 1 0 0 5.0000 2.2361 ENUM('2','4','6','8') NOT NULL t1.j 2 8 1 1 0 0 5.0000 2.2361 ENUM('2','4','6','8') NOT NULL
t1.empty_string 0 0 4 0 0.0000 NULL ENUM('') NOT NULL
t1.bool N Y 1 1 0 0 1.0000 NULL ENUM('N','Y') NOT NULL
t1.d 2002-03-04 10 10 0 0 10.0000 NULL ENUM('2002-03-03','2002-03-04','2002-03-05') NOT NULL
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
# Test of procedure analyse # Test of procedure analyse
# #
create table t1 (i int, j int); create table t1 (i int, j int, empty_string char(10), bool char(1), d date);
insert into t1 values (1,2), (3,4), (5,6), (7,8); insert into t1 values (1,2,"","Y","2002-03-03"), (3,4,"","N","2002-03-04"), (5,6,"","Y","2002-03-04"), (7,8,"","N","2002-03-05");
select * from t1 procedure analyse(); select * from t1 procedure analyse();
select * from t1 procedure analyse(2);
create table t2 select * from t1 procedure analyse(); create table t2 select * from t1 procedure analyse();
select * from t2; select * from t2;
drop table t1,t2; drop table t1,t2;
...@@ -122,12 +122,15 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result, ...@@ -122,12 +122,15 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
*f_info++ = new field_str(item, pc); *f_info++ = new field_str(item, pc);
} }
return pc; return pc;
} // proc_analyse_init }
/*
Return 1 if number, else return 0
store info about found number in info
NOTE:It is expected, that elements of 'info' are all zero!
*/
// return 1 if number, else return 0
// store info about found number in info
// NOTE:It is expected, that elements of 'info' are all zero!
bool test_if_number(NUM_INFO *info, const char *str, uint str_len) bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
{ {
const char *begin, *end = str + str_len; const char *begin, *end = str + str_len;
...@@ -205,14 +208,16 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len) ...@@ -205,14 +208,16 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
} }
else else
return 0; return 0;
} //test_if_number }
// Stores the biggest and the smallest value from current 'info' /*
// to ev_num_info Stores the biggest and the smallest value from current 'info'
// If info contains an ulonglong number, which is bigger than to ev_num_info
// biggest positive number able to be stored in a longlong variable If info contains an ulonglong number, which is bigger than
// and is marked as negative, function will return 0, else 1. biggest positive number able to be stored in a longlong variable
and is marked as negative, function will return 0, else 1.
*/
bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num) bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num)
{ {
...@@ -240,11 +245,13 @@ void free_string(String *s) ...@@ -240,11 +245,13 @@ void free_string(String *s)
s->free(); s->free();
} }
void field_str::add() void field_str::add()
{ {
char buff[MAX_FIELD_WIDTH], *ptr; char buff[MAX_FIELD_WIDTH], *ptr;
String s(buff, sizeof(buff)), *res; String s(buff, sizeof(buff)), *res;
ulong length; ulong length;
TREE_ELEMENT *element;
if (!(res = item->val_str(&s))) if (!(res = item->val_str(&s)))
{ {
...@@ -285,7 +292,7 @@ void field_str::add() ...@@ -285,7 +292,7 @@ void field_str::add()
if (!tree_search(&tree, (void*) &s)) // If not in tree if (!tree_search(&tree, (void*) &s)) // If not in tree
{ {
s.copy(); // slow, when SAFE_MALLOC is in use s.copy(); // slow, when SAFE_MALLOC is in use
if (!tree_insert(&tree, (void*) &s, 0)) if (!(element=tree_insert(&tree, (void*) &s, 0)))
{ {
room_in_tree = 0; // Remove tree, out of RAM ? room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree); delete_tree(&tree);
...@@ -293,7 +300,9 @@ void field_str::add() ...@@ -293,7 +300,9 @@ void field_str::add()
else else
{ {
bzero((char*) &s, sizeof(s)); // Let tree handle free of this bzero((char*) &s, sizeof(s)); // Let tree handle free of this
if ((treemem += length) > pc->max_treemem) if ((treemem += length) > pc->max_treemem ||
(element->count == 1 &&
(tree_elements++) >= pc->max_tree_elements))
{ {
room_in_tree = 0; // Remove tree, too big tree room_in_tree = 0; // Remove tree, too big tree
delete_tree(&tree); delete_tree(&tree);
...@@ -389,9 +398,11 @@ void field_real::add() ...@@ -389,9 +398,11 @@ void field_real::add()
room_in_tree = 0; // Remove tree, out of RAM ? room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree); delete_tree(&tree);
} }
// if element->count == 1, this element can be found only once from tree /*
// if element->count == 2, or more, this element is already in tree if element->count == 1, this element can be found only once from tree
else if (element->count == 1 && (tree_elements++) > pc->max_tree_elements) if element->count == 2, or more, this element is already in tree
*/
else if (element->count == 1 && (tree_elements++) >= pc->max_tree_elements)
{ {
room_in_tree = 0; // Remove tree, too many elements room_in_tree = 0; // Remove tree, too many elements
delete_tree(&tree); delete_tree(&tree);
...@@ -420,6 +431,7 @@ void field_real::add() ...@@ -420,6 +431,7 @@ void field_real::add()
} }
} // field_real::add } // field_real::add
void field_longlong::add() void field_longlong::add()
{ {
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
...@@ -442,9 +454,11 @@ void field_longlong::add() ...@@ -442,9 +454,11 @@ void field_longlong::add()
room_in_tree = 0; // Remove tree, out of RAM ? room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree); delete_tree(&tree);
} }
// if element->count == 1, this element can be found only once from tree /*
// if element->count == 2, or more, this element is already in tree if element->count == 1, this element can be found only once from tree
else if (element->count == 1 && (tree_elements++) > pc->max_tree_elements) if element->count == 2, or more, this element is already in tree
*/
else if (element->count == 1 && (tree_elements++) >= pc->max_tree_elements)
{ {
room_in_tree = 0; // Remove tree, too many elements room_in_tree = 0; // Remove tree, too many elements
delete_tree(&tree); delete_tree(&tree);
...@@ -496,9 +510,11 @@ void field_ulonglong::add() ...@@ -496,9 +510,11 @@ void field_ulonglong::add()
room_in_tree = 0; // Remove tree, out of RAM ? room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree); delete_tree(&tree);
} }
// if element->count == 1, this element can be found only once from tree /*
// if element->count == 2, or more, this element is already in tree if element->count == 1, this element can be found only once from tree
else if (element->count == 1 && (tree_elements++) > pc->max_tree_elements) if element->count == 2, or more, this element is already in tree
*/
else if (element->count == 1 && (tree_elements++) >= pc->max_tree_elements)
{ {
room_in_tree = 0; // Remove tree, too many elements room_in_tree = 0; // Remove tree, too many elements
delete_tree(&tree); delete_tree(&tree);
...@@ -578,14 +594,16 @@ bool analyse::end_of_records() ...@@ -578,14 +594,16 @@ bool analyse::end_of_records()
func_items[8]->null_value = 1; func_items[8]->null_value = 1;
else else
func_items[8]->set(res->ptr(), res->length()); func_items[8]->set(res->ptr(), res->length());
// count the dots, quotas, etc. in (ENUM("a","b","c"...)) /*
// if tree has been removed, don't suggest ENUM. count the dots, quotas, etc. in (ENUM("a","b","c"...))
// treemem is used to measure the size of tree for strings, If tree has been removed, don't suggest ENUM.
// tree_elements is used to count the elements in tree in case of numbers. treemem is used to measure the size of tree for strings,
// max_treemem tells how long the string starting from ENUM("... and tree_elements is used to count the elements
// ending to ..") shall at maximum be. If case is about numbers, max_treemem tells how long the string starting from ENUM("... and
// max_tree_elements will tell the length of the above, now ending to ..") shall at maximum be. If case is about numbers,
// every number is considered as length 1 max_tree_elements will tell the length of the above, now
every number is considered as length 1
*/
if (((*f)->treemem || (*f)->tree_elements) && if (((*f)->treemem || (*f)->tree_elements) &&
(*f)->tree.elements_in_tree && (*f)->tree.elements_in_tree &&
(((*f)->treemem ? max_treemem : max_tree_elements) > (((*f)->treemem ? max_treemem : max_tree_elements) >
...@@ -628,6 +646,7 @@ bool analyse::end_of_records() ...@@ -628,6 +646,7 @@ bool analyse::end_of_records()
ans.append("DATETIME", 8); ans.append("DATETIME", 8);
break; break;
case FIELD_TYPE_DATE: case FIELD_TYPE_DATE:
case FIELD_TYPE_NEWDATE:
ans.append("DATE", 4); ans.append("DATE", 4);
break; break;
case FIELD_TYPE_SET: case FIELD_TYPE_SET:
...@@ -639,9 +658,6 @@ bool analyse::end_of_records() ...@@ -639,9 +658,6 @@ bool analyse::end_of_records()
case FIELD_TYPE_TIME: case FIELD_TYPE_TIME:
ans.append("TIME", 4); ans.append("TIME", 4);
break; break;
case FIELD_TYPE_NEWDATE:
ans.append("NEWDATE", 7);
break;
case FIELD_TYPE_DECIMAL: case FIELD_TYPE_DECIMAL:
ans.append("DECIMAL", 7); ans.append("DECIMAL", 7);
// if item is FIELD_ITEM, it _must_be_ Field_num in this case // if item is FIELD_ITEM, it _must_be_ Field_num in this case
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment