mirror of
				https://github.com/MariaDB/server.git
				synced 2025-10-31 15:50:51 +03:00 
			
		
		
		
	 8cfe729678
			
		
	
	8cfe729678
	
	
	
		
			
			not default_charset_into. It fixes the problem that in some cases numbers where treated as CHAR(N), not as BINARY(N), e.g. wrong 'charsetnr' when sent to the client side. 2. IFNULL didn't aggregate argument charsets and collations, so IFNULL(1,'a') produced a CHAR(N). Now produces a BINARY(N). 3. SELECT PROCEDURE ANALIZE now returns BINARY columns, which is much better than it worked previously: CHAR with the default character set. But in the future it's worth to fix the fields 'Field_name' and 'Optimal_fieldtype' to use UTF8, and 'Min_value' and 'Max_value' to inherit their charsets from the original items. But it is not important, and BINARY(N) is OK for now. 4. Tests were fixed accordingly. No new tests were made, as the old onces cover everything.
		
			
				
	
	
		
			105 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			105 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| drop table if exists t1,t2;
 | |
| create table t1 (i int, j int, empty_string char(10), bool char(1), d date);
 | |
| 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 count(*) from t1 procedure analyse();
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| count(*)	4	4	1	1	0	0	4.0000	0.0000	ENUM('4') NOT NULL
 | |
| select * from t1 procedure analyse();
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| test.t1.i	1	7	1	1	0	0	4.0000	2.2361	ENUM('1','3','5','7') NOT NULL
 | |
| test.t1.j	2	8	1	1	0	0	5.0000	2.2361	ENUM('2','4','6','8') NOT NULL
 | |
| test.t1.empty_string			0	0	4	0	0.0000	NULL	CHAR(0) NOT NULL
 | |
| test.t1.bool	N	Y	1	1	0	0	1.0000	NULL	ENUM('N','Y') NOT NULL
 | |
| test.t1.d	2002-03-03	2002-03-05	10	10	0	0	10.0000	NULL	ENUM('2002-03-03','2002-03-04','2002-03-05') NOT NULL
 | |
| select * from t1 procedure analyse(2);
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| test.t1.i	1	7	1	1	0	0	4.0000	2.2361	TINYINT(1) UNSIGNED NOT NULL
 | |
| test.t1.j	2	8	1	1	0	0	5.0000	2.2361	TINYINT(1) UNSIGNED NOT NULL
 | |
| test.t1.empty_string			0	0	4	0	0.0000	NULL	CHAR(0) NOT NULL
 | |
| test.t1.bool	N	Y	1	1	0	0	1.0000	NULL	ENUM('N','Y') NOT NULL
 | |
| test.t1.d	2002-03-03	2002-03-05	10	10	0	0	10.0000	NULL	ENUM('2002-03-03','2002-03-04','2002-03-05') NOT NULL
 | |
| create table t2 select * from t1 procedure analyse();
 | |
| select * from t2;
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| test.t1.i	1	7	1	1	0	0	4.0000	2.2361	ENUM('1','3','5','7') NOT NULL
 | |
| test.t1.j	2	8	1	1	0	0	5.0000	2.2361	ENUM('2','4','6','8') NOT NULL
 | |
| test.t1.empty_string			0	0	4	0	0.0000	NULL	CHAR(0) NOT NULL
 | |
| test.t1.bool	N	Y	1	1	0	0	1.0000	NULL	ENUM('N','Y') NOT NULL
 | |
| test.t1.d	2002-03-03	2002-03-05	10	10	0	0	10.0000	NULL	ENUM('2002-03-03','2002-03-04','2002-03-05') NOT NULL
 | |
| drop table t1,t2;
 | |
| EXPLAIN SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE();
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
 | |
| 2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
 | |
| create table t1 (a int not null);
 | |
| create table t2 select * from t1 where 0=1 procedure analyse();
 | |
| show create table t2;
 | |
| Table	Create Table
 | |
| t2	CREATE TABLE `t2` (
 | |
|   `Field_name` binary(255) NOT NULL default '',
 | |
|   `Min_value` binary(255) default NULL,
 | |
|   `Max_value` binary(255) default NULL,
 | |
|   `Min_length` bigint(11) NOT NULL default '0',
 | |
|   `Max_length` bigint(11) NOT NULL default '0',
 | |
|   `Empties_or_zeros` bigint(11) NOT NULL default '0',
 | |
|   `Nulls` bigint(11) NOT NULL default '0',
 | |
|   `Avg_value_or_avg_length` binary(255) NOT NULL default '',
 | |
|   `Std` binary(255) default NULL,
 | |
|   `Optimal_fieldtype` binary(64) NOT NULL default ''
 | |
| ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 | |
| select * from t1 where 0=1 procedure analyse();
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| insert into t1 values(1);
 | |
| drop table t2;
 | |
| create table t2 select * from t1 where 0=1 procedure analyse();
 | |
| show create table t2;
 | |
| Table	Create Table
 | |
| t2	CREATE TABLE `t2` (
 | |
|   `Field_name` binary(255) NOT NULL default '',
 | |
|   `Min_value` binary(255) default NULL,
 | |
|   `Max_value` binary(255) default NULL,
 | |
|   `Min_length` bigint(11) NOT NULL default '0',
 | |
|   `Max_length` bigint(11) NOT NULL default '0',
 | |
|   `Empties_or_zeros` bigint(11) NOT NULL default '0',
 | |
|   `Nulls` bigint(11) NOT NULL default '0',
 | |
|   `Avg_value_or_avg_length` binary(255) NOT NULL default '',
 | |
|   `Std` binary(255) default NULL,
 | |
|   `Optimal_fieldtype` binary(64) NOT NULL default ''
 | |
| ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 | |
| select * from t2;
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| insert into t2 select * from t1 procedure analyse();
 | |
| select * from t2;
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| test.t1.a	1	1	1	1	0	0	1.0000	0.0000	ENUM('1') NOT NULL
 | |
| insert into t1 values(2);
 | |
| drop table t2;
 | |
| create table t2 select * from t1 where 0=1 procedure analyse();
 | |
| show create table t2;
 | |
| Table	Create Table
 | |
| t2	CREATE TABLE `t2` (
 | |
|   `Field_name` binary(255) NOT NULL default '',
 | |
|   `Min_value` binary(255) default NULL,
 | |
|   `Max_value` binary(255) default NULL,
 | |
|   `Min_length` bigint(11) NOT NULL default '0',
 | |
|   `Max_length` bigint(11) NOT NULL default '0',
 | |
|   `Empties_or_zeros` bigint(11) NOT NULL default '0',
 | |
|   `Nulls` bigint(11) NOT NULL default '0',
 | |
|   `Avg_value_or_avg_length` binary(255) NOT NULL default '',
 | |
|   `Std` binary(255) default NULL,
 | |
|   `Optimal_fieldtype` binary(64) NOT NULL default ''
 | |
| ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 | |
| select * from t2;
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| insert into t2 select * from t1 procedure analyse();
 | |
| select * from t2;
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| test.t1.a	1	2	1	1	0	0	1.5000	0.5000	ENUM('1','2') NOT NULL
 | |
| drop table t1,t2;
 | |
| create table t1 (v varchar(128));
 | |
| insert into t1 values ('abc'),('abc\'def\\hij\"klm\0opq'),('\''),('\"'),('\\'),('a\0'),('b\''),('c\"'),('d\\'),('\'b'),('\"c'),('\\d'),('a\0\0\0b'),('a\'\'\'\'b'),('a\"\"\"\"b'),('a\\\\\\\\b'),('\'\0\\\"'),('\'\''),('\"\"'),('\\\\'),('The\ZEnd');
 | |
| select * from t1 procedure analyse();
 | |
| Field_name	Min_value	Max_value	Min_length	Max_length	Empties_or_zeros	Nulls	Avg_value_or_avg_length	Std	Optimal_fieldtype
 | |
| test.t1.v	"	\\	1	19	0	0	3.7619	NULL	ENUM('"','""','"c','\'\0\\"','\'','\'\'','\'b','a\0\0\0b','a\0','a""""b','a\'\'\'\'b','abc','abc\'def\\hij"klm\0opq','a\\\\\\\\b','b\'','c"','d\\','The\ZEnd','\\','\\d','\\\\') NOT NULL
 | |
| drop table t1;
 |