mirror of
				https://github.com/MariaDB/server.git
				synced 2025-10-31 02:46:29 +01:00 
			
		
		
		
	 3bdc5542dc
			
		
	
	
	3bdc5542dc
	
	
	
		
			
			Introduces @@optimizer_switch flag: hash_join_cardinality When this option is on, use EITS statistics to produce tighter bounds for hash join output cardinality. This patch is an extension / replacement to a similar patch in 10.6 New features: - optimizer_switch hash_join_cardinality is on by default - records_out is set to fanout when HASH is used - Fixed bug in is_eits_usable: The function did not work with views
		
			
				
	
	
		
			105 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			105 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| create table t1 (a int, b int, c int);
 | |
| insert into t1 select seq,seq/2, seq/4 from seq_1_to_100;
 | |
| create table t2 (a int, b int, c int);
 | |
| insert into t2 select seq, seq/2, seq/4 from seq_1_to_200;
 | |
| analyze table t1,t2 persistent for all;
 | |
| Table	Op	Msg_type	Msg_text
 | |
| test.t1	analyze	status	Engine-independent statistics collected
 | |
| test.t1	analyze	status	OK
 | |
| test.t2	analyze	status	Engine-independent statistics collected
 | |
| test.t2	analyze	status	OK
 | |
| set optimizer_trace=1;
 | |
| set join_cache_level=6;
 | |
| set optimizer_switch='hash_join_cardinality=on';
 | |
| explain select *
 | |
| from t1, t2
 | |
| where t1.a=t2.a and t1.a=t2.b and t1.c=t2.c;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	100	Using where
 | |
| 1	SIMPLE	t2	hash_ALL	NULL	#hash#$hj	15	test.t1.a,test.t1.a,test.t1.c	200	Using where; Using join buffer (flat, BNLH join)
 | |
| set @json= (select trace from information_schema.optimizer_trace);
 | |
| select json_detailed(json_extract(@json, '$**.hash_join_cardinality')) as JS;
 | |
| JS
 | |
| [
 | |
|     {
 | |
|         "hash_join_columns": 
 | |
|         [
 | |
|             {
 | |
|                 "field": "a",
 | |
|                 "avg_frequency": 1
 | |
|             },
 | |
|             {
 | |
|                 "field": "b",
 | |
|                 "avg_frequency": 2
 | |
|             },
 | |
|             {
 | |
|                 "field": "c",
 | |
|                 "avg_frequency": 3.9216
 | |
|             }
 | |
|         ],
 | |
|         "rows": 1
 | |
|     }
 | |
| ]
 | |
| select json_detailed(json_extract(@json, '$**.rest_of_plan[*].rows_for_plan'))
 | |
| as ROWS_FOR_PLAN;
 | |
| ROWS_FOR_PLAN
 | |
| [100]
 | |
| explain select *
 | |
| from t1, t2 where t1.c=t2.c;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	100	Using where
 | |
| 1	SIMPLE	t2	hash_ALL	NULL	#hash#$hj	5	test.t1.c	200	Using where; Using join buffer (flat, BNLH join)
 | |
| set @json= (select trace from information_schema.optimizer_trace);
 | |
| select json_detailed(json_extract(@json, '$**.hash_join_cardinality')) as JS;
 | |
| JS
 | |
| [
 | |
|     {
 | |
|         "hash_join_columns": 
 | |
|         [
 | |
|             {
 | |
|                 "field": "c",
 | |
|                 "avg_frequency": 3.9216
 | |
|             }
 | |
|         ],
 | |
|         "rows": 3.9216
 | |
|     }
 | |
| ]
 | |
| select json_detailed(json_extract(@json, '$**.rest_of_plan[*].rows_for_plan'))
 | |
| as ROWS_FOR_PLAN;
 | |
| ROWS_FOR_PLAN
 | |
| [392.16]
 | |
| explain select *
 | |
| from t1 straight_join t2 where t1.c=t2.c and t2.a<30;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	100	Using where
 | |
| 1	SIMPLE	t2	hash_ALL	NULL	#hash#$hj	5	test.t1.c	200	Using where; Using join buffer (flat, BNLH join)
 | |
| set @json= (select trace from information_schema.optimizer_trace);
 | |
| # Note that rows is the same:
 | |
| select json_detailed(json_extract(@json, '$**.hash_join_cardinality')) as JS;
 | |
| JS
 | |
| [
 | |
|     {
 | |
|         "hash_join_columns": 
 | |
|         [
 | |
|             {
 | |
|                 "field": "c",
 | |
|                 "avg_frequency": 3.9216
 | |
|             }
 | |
|         ],
 | |
|         "rows": 0.568632
 | |
|     }
 | |
| ]
 | |
| # Despite available selectivity:
 | |
| select json_detailed(json_extract(@json, '$**.selectivity_for_columns')) as JS;
 | |
| JS
 | |
| [
 | |
|     [
 | |
|         {
 | |
|             "column_name": "a",
 | |
|             "ranges": 
 | |
|             ["NULL < a < 30"],
 | |
|             "selectivity_from_histogram": 0.145
 | |
|         }
 | |
|     ]
 | |
| ]
 | |
| drop table t1,t2;
 |