optimizer_search_depth探讨

10.1背景:模拟通过多表查询以分类为分组查询分类中的节目数

10.2建表语句(由于实际应用的表,删除了部分字段)

mysql> show create table movies\G;

*************************** 1. row ***************************

Table: movies

Create Table: CREATE TABLE `movies` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`title` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT ‘‘,

`mpeg` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT ‘‘,

`pre_mpeg` varchar(255) CHARACTER SET latin1 DEFAULT ‘‘,

`genre` int(11) DEFAULT ‘1‘,

`icp` int(11) DEFAULT ‘1‘,

.....

`is_section` int(11) DEFAULT ‘0‘,

`keyword` varchar(255) CHARACTER SET latin1 DEFAULT NULL,

`movie_type` varchar(255) CHARACTER SET latin1 DEFAULT NULL,

`sourcetype` int(11) DEFAULT ‘0‘,

`pre_mpeg_type` int(11) DEFAULT ‘0‘,

`fenbianlv` varchar(255) CHARACTER SET latin1 DEFAULT NULL,

`look_focus` varchar(255) CHARACTER SET latin1 DEFAULT NULL,

`play_time` varchar(20) CHARACTER SET latin1 DEFAULT NULL,

`downline_time` varchar(20) CHARACTER SET latin1 DEFAULT NULL,

`channelcode` varchar(255) CHARACTER SET latin1 DEFAULT NULL,

`uniquecode` varchar(64) CHARACTER SET latin1 NOT NULL DEFAULT ‘‘,

PRIMARY KEY (`id`),

UNIQUE KEY `mpeg_index` (`mpeg`),

KEY `title_index` (`title`),

KEY `genre_index` (`genre`),

KEY `tele_index` (`teleplaycode`,`movie_order`),

KEY `count_index` (`isdel`,`auditing`),

KEY `madein_index` (`madein`),

KEY `keyword_index` (`keyword`),

KEY `movie_type_index` (`movie_type`),

KEY `index_imgname` (`image_name`),

KEY `uniquecode_index` (`uniquecode`),

KEY `actor` (`actor`),

KEY `actor1` (`actor1`),

KEY `director` (`director`)

) ENGINE=MyISAM AUTO_INCREMENT=160715 DEFAULT CHARSET=utf8

1 row in set (0.00 sec)

id为主键,genre列有索引

mysql> show create table standard_menu\G;

*************************** 1. row ***************************

Table: standard_menu

Create Table: CREATE TABLE `standard_menu` (

`id` varchar(64) NOT NULL DEFAULT ‘‘,

`parent_id` varchar(64) NOT NULL DEFAULT ‘0‘,

`name` varchar(128) NOT NULL DEFAULT ‘‘,

`service_code` varchar(32) DEFAULT NULL,

`keyword` varchar(255) DEFAULT NULL,

`language` int(11) DEFAULT ‘0‘,

`menu_kind` int(11) DEFAULT ‘0‘,

`position` int(11) DEFAULT ‘99‘,

`genre_id` int(11) DEFAULT NULL,

......

`lck_mark` char(1) DEFAULT ‘0‘,

`coll_state` char(1) DEFAULT ‘0‘,

`search_range` varchar(10) DEFAULT NULL,

`search_value` varchar(255) DEFAULT NULL,

`sel_info` varchar(255) DEFAULT NULL,

`menu_style` int(11) DEFAULT ‘0‘,

`cp_id` int(11) DEFAULT ‘0‘,

`reserve_info` text,

`menu_remark` text,

PRIMARY KEY (`id`),

KEY `Index_sel` (`parent_id`,`position`),

KEY `index_lock` (`lck_mark`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1

1 row in set (0.00 sec)

id为主键,genre列无索引

mysql> show create table genre\G;

*************************** 1. row ***************************

Table: genre

Create Table: CREATE TABLE `genre` (

`gen_id` double DEFAULT NULL,

`gen_name` varchar(765) DEFAULT NULL,

`gen_seq` tinyint(4) DEFAULT NULL,

`gen_level` varchar(765) DEFAULT NULL,

`display_order` varchar(120) DEFAULT NULL,

KEY `genre_gen_id_idx` (`gen_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1

1 row in set (0.00 sec)

mysql> show create table menu_movie\G;

*************************** 1. row ***************************

Table: menu_movie

Create Table: CREATE TABLE `menu_movie` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`menu_code` varchar(64) NOT NULL DEFAULT ‘0‘,

`movie_id` int(11) DEFAULT NULL,

`movie_mpeg` varchar(255) NOT NULL DEFAULT ‘0‘,

`movie_order` int(11) DEFAULT NULL,

PRIMARY KEY (`id`),

KEY `menu_movie_menu_code_idx` (`menu_code`)

) ENGINE=MyISAM AUTO_INCREMENT=12374 DEFAULT CHARSET=latin1

1 row in set (0.00 sec)

10.3查询语句

mysql> explain extended select a.genre,count(*) from movies a

-> join genre b on b.gen_id=a.genre

-> join standard_menu c on b.gen_id=c.genre_id

-> join menu_movie d

-> where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code

-> group by a.genre having count(*)>10

-> order by a.id desc;

10.4打开与关闭bka算法的示例:

10.4.1关闭

默认是关闭的。也可以手工关闭:

mysql> SET optimizer_switch=‘mrr=off,mrr_cost_based=on,batched_key_access=off‘;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+----------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                        |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+----------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where                                  |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                     |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where                                  |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+----------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

10.4.1打开

mysql> SET optimizer_switch=‘mrr=on,mrr_cost_based=off,batched_key_access=on‘;

Query OK, 0 rows affected (0.00 sec)

10.5探讨bka参数设置

MySQL里限制一个查询的join表数目上限为61,对于一个有61个表参与的join操作,理论上需要61!(阶乘)次的评估。在多表join的场景下,为了避免优化器占用太多时间,MySQL提供了一个参数 optimizer_search_depth 来控制递归深度。这个参数对算法的控制可以简单描述为:对于所有的排列,只取前当前join顺序的前optimizer_search_depth个表估算代价。举例来说,20张表的,假设optimizer_search_depth为4,那么评估次数为20*19*18*17。

怎么选择参数optimizer_search_depth的值?MySQL中optimizer_search_depth默认值为62.也就是说默认为全排列计算。

曾试图找到什么规律,暂时也没找到。

寻找思路如下:

(1)optimizer_prune_level=0情况下,查询执行计划情况;

(2)optimizer_prune_level=1情况下,查询执行计划情况。

10.5.1optimizer_prune_level=0情况

mysql> set optimizer_prune_level=0;

Query OK, 0 rows affected (0.01 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> set profiling=1;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> set optimizer_search_depth=0;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

optimizer_search_depth=0与默认情况下的执行计划基本相同。

mysql> show profile for query 237;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000172 |

| checking permissions | 0.000010 |

| checking permissions | 0.000008 |

| checking permissions | 0.000006 |

| checking permissions | 0.000010 |

| Opening tables       | 0.000111 |

| init                 | 0.000052 |

| System lock          | 0.000073 |

| optimizing           | 0.000030 |

| statistics           | 0.000268 |

| preparing            | 0.000038 |

| Creating tmp table   | 0.000032 |

| Sorting result       | 0.000009 |

| explaining           | 0.000071 |

| query end            | 0.000013 |

| removing tmp table   | 0.000007 |

| query end            | 0.000007 |

| closing tables       | 0.000014 |

| freeing items        | 0.000142 |

| cleaning up          | 0.000403 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

查询持续时间为0.000268s

mysql> set optimizer_search_depth=1;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+--------------------------+---------+----------------------+------+----------+---------------------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key                      | key_len | ref                  | rows | filtered | Extra                                                         |

+----+-------------+-------+--------+--------------------------+--------------------------+---------+----------------------+------+----------+---------------------------------------------------------------+

|  1 | SIMPLE      | b     | index  | genre_gen_id_idx         | genre_gen_id_idx         | 9       | NULL                 |  376 |    99.47 | Using where; Using index; Using temporary; Using filesort     |

|  1 | SIMPLE      | c     | ref    | PRIMARY,ind_genre_id     | ind_genre_id             | 5       | Portal_19.b.gen_id   |    4 |   100.00 | Using index condition; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | d     | ref    | menu_movie_menu_code_idx | menu_movie_menu_code_idx | 66      | Portal_19.c.id       |    3 |   100.00 | Using where; Using join buffer (Batched Key Access)           |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY                  | 4       | Portal_19.d.movie_id |    1 |   100.00 | Using where; Using join buffer (Batched Key Access)           |

+----+-------------+-------+--------+--------------------------+--------------------------+---------+----------------------+------+----------+---------------------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 239;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000225 |

| checking permissions | 0.000013 |

| checking permissions | 0.000031 |

| checking permissions | 0.000006 |

| checking permissions | 0.000011 |

| Opening tables       | 0.000125 |

| init                 | 0.000058 |

| System lock          | 0.000035 |

| optimizing           | 0.000027 |

| statistics           | 0.000241 |

| preparing            | 0.000069 |

| Creating tmp table   | 0.000037 |

| Sorting result       | 0.000009 |

| explaining           | 0.000087 |

| query end            | 0.000017 |

| removing tmp table   | 0.000008 |

| query end            | 0.000006 |

| closing tables       | 0.000015 |

| freeing items        | 0.000968 |

| cleaning up          | 0.000138 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

在optimizer_search_depth=1时,即评估次数为4,表的扫描顺序为bcda。似乎这种情况是最优的。但所有的扫描持续时间有都比其他情况下时间长?

下面的optimizer_search_depth=2-6,表的扫描顺序为dcba,所有的扫描持续时间基本相同。

mysql> set optimizer_search_depth=2;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 241;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000313 |

| checking permissions | 0.000017 |

| checking permissions | 0.000006 |

| checking permissions | 0.000005 |

| checking permissions | 0.000013 |

| Opening tables       | 0.000146 |

| init                 | 0.000065 |

| System lock          | 0.000062 |

| optimizing           | 0.000033 |

| statistics           | 0.000143 |

| preparing            | 0.000066 |

| Creating tmp table   | 0.000037 |

| Sorting result       | 0.000009 |

| explaining           | 0.000079 |

| query end            | 0.000018 |

| removing tmp table   | 0.000007 |

| query end            | 0.000007 |

| closing tables       | 0.000016 |

| freeing items        | 0.000848 |

| cleaning up          | 0.000091 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

mysql>

mysql> set optimizer_search_depth=3;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 243;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000194 |

| checking permissions | 0.000013 |

| checking permissions | 0.000007 |

| checking permissions | 0.000007 |

| checking permissions | 0.000012 |

| Opening tables       | 0.000123 |

| init                 | 0.000101 |

| System lock          | 0.000044 |

| optimizing           | 0.000035 |

| statistics           | 0.000162 |

| preparing            | 0.000036 |

| Creating tmp table   | 0.000073 |

| Sorting result       | 0.000012 |

| explaining           | 0.000118 |

| query end            | 0.000018 |

| removing tmp table   | 0.000009 |

| query end            | 0.000008 |

| closing tables       | 0.000027 |

| freeing items        | 0.001002 |

| cleaning up          | 0.000075 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

mysql> set optimizer_search_depth=4;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 245;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000247 |

| checking permissions | 0.000016 |

| checking permissions | 0.000007 |

| checking permissions | 0.000007 |

| checking permissions | 0.000011 |

| Opening tables       | 0.000117 |

| init                 | 0.000088 |

| System lock          | 0.000039 |

| optimizing           | 0.000030 |

| statistics           | 0.000430 |

| preparing            | 0.000065 |

| Creating tmp table   | 0.000035 |

| Sorting result       | 0.000010 |

| explaining           | 0.000082 |

| query end            | 0.000019 |

| removing tmp table   | 0.000009 |

| query end            | 0.000007 |

| closing tables       | 0.000017 |

| freeing items        | 0.000042 |

| cleaning up          | 0.000023 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

mysql>

mysql> set optimizer_search_depth=5;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 247;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000170 |

| checking permissions | 0.000034 |

| checking permissions | 0.000006 |

| checking permissions | 0.000006 |

| checking permissions | 0.000008 |

| Opening tables       | 0.000104 |

| init                 | 0.000079 |

| System lock          | 0.000036 |

| optimizing           | 0.000029 |

| statistics           | 0.000151 |

| preparing            | 0.000037 |

| Creating tmp table   | 0.000033 |

| Sorting result       | 0.000009 |

| explaining           | 0.000062 |

| query end            | 0.000015 |

| removing tmp table   | 0.000007 |

| query end            | 0.000006 |

| closing tables       | 0.000032 |

| freeing items        | 0.000035 |

| cleaning up          | 0.000020 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

mysql>

mysql> set optimizer_search_depth=6;

Query OK, 0 rows affected (0.01 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.01 sec)

mysql> show profile for query 249;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000095 |

| checking permissions | 0.000015 |

| checking permissions | 0.000008 |

| checking permissions | 0.000006 |

| checking permissions | 0.000126 |

| Opening tables       | 0.000124 |

| init                 | 0.000061 |

| System lock          | 0.000063 |

| optimizing           | 0.000033 |

| statistics           | 0.000162 |

| preparing            | 0.000071 |

| Creating tmp table   | 0.000036 |

| Sorting result       | 0.000010 |

| explaining           | 0.000081 |

| query end            | 0.000016 |

| removing tmp table   | 0.000008 |

| query end            | 0.000008 |

| closing tables       | 0.000017 |

| freeing items        | 0.000761 |

| cleaning up          | 0.000062 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

10.5.2optimizer_prune_level=1情况

mysql> select @@optimizer_prune_level;

+-------------------------+

| @@optimizer_prune_level |

+-------------------------+

|                       0 |

+-------------------------+

1 row in set (0.01 sec)

mysql> set optimizer_prune_level=1;

Query OK, 0 rows affected (0.00 sec)

mysql> set optimizer_search_depth=0;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 253;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000311 |

| checking permissions | 0.000016 |

| checking permissions | 0.000006 |

| checking permissions | 0.000006 |

| checking permissions | 0.000011 |

| Opening tables       | 0.000165 |

| init                 | 0.000068 |

| System lock          | 0.000042 |

| optimizing           | 0.000030 |

| statistics           | 0.000149 |

| preparing            | 0.000044 |

| Creating tmp table   | 0.000039 |

| Sorting result       | 0.000009 |

| explaining           | 0.000116 |

| query end            | 0.000018 |

| removing tmp table   | 0.000008 |

| query end            | 0.000007 |

| closing tables       | 0.000016 |

| freeing items        | 0.000800 |

| cleaning up          | 0.000095 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

mysql>

mysql> set optimizer_search_depth=1;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+--------------------------+---------+----------------------+------+----------+---------------------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key                      | key_len | ref                  | rows | filtered | Extra                                                         |

+----+-------------+-------+--------+--------------------------+--------------------------+---------+----------------------+------+----------+---------------------------------------------------------------+

|  1 | SIMPLE      | b     | index  | genre_gen_id_idx         | genre_gen_id_idx         | 9       | NULL                 |  376 |    99.47 | Using where; Using index; Using temporary; Using filesort     |

|  1 | SIMPLE      | c     | ref    | PRIMARY,ind_genre_id     | ind_genre_id             | 5       | Portal_19.b.gen_id   |    4 |   100.00 | Using index condition; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | d     | ref    | menu_movie_menu_code_idx | menu_movie_menu_code_idx | 66      | Portal_19.c.id       |    3 |   100.00 | Using where; Using join buffer (Batched Key Access)           |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY                  | 4       | Portal_19.d.movie_id |    1 |   100.00 | Using where; Using join buffer (Batched Key Access)           |

+----+-------------+-------+--------+--------------------------+--------------------------+---------+----------------------+------+----------+---------------------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 255;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000139 |

| checking permissions | 0.000011 |

| checking permissions | 0.000006 |

| checking permissions | 0.000006 |

| checking permissions | 0.000008 |

| Opening tables       | 0.000106 |

| init                 | 0.000051 |

| System lock          | 0.000036 |

| optimizing           | 0.000030 |

| statistics           | 0.000174 |

| preparing            | 0.000041 |

| Creating tmp table   | 0.000034 |

| Sorting result       | 0.000009 |

| explaining           | 0.000085 |

| query end            | 0.000014 |

| removing tmp table   | 0.000008 |

| query end            | 0.000007 |

| closing tables       | 0.000016 |

| freeing items        | 0.000819 |

| cleaning up          | 0.000059 |

+----------------------+----------+

20 rows in set, 1 warning (0.01 sec)

在optimizer_search_depth=1时,即评估次数为4,表的扫描顺序为bcda。似乎这种情况是最优的。但所有的扫描持续时间与其他情况下基本相同,与在optimizer_prune_level=0情况下基本相同。

下面的optimizer_search_depth=2-6,表的扫描顺序为dcba,所有的扫描持续时间基本相同。或许是数据量小的缘故,没测试出什么来。

mysql>

mysql> set optimizer_search_depth=2;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.01 sec)

mysql> show profile for query 257;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000167 |

| checking permissions | 0.000014 |

| checking permissions | 0.000005 |

| checking permissions | 0.000006 |

| checking permissions | 0.000008 |

| Opening tables       | 0.000113 |

| init                 | 0.000086 |

| System lock          | 0.000037 |

| optimizing           | 0.000027 |

| statistics           | 0.000137 |

| preparing            | 0.000041 |

| Creating tmp table   | 0.000035 |

| Sorting result       | 0.000009 |

| explaining           | 0.000075 |

| query end            | 0.000015 |

| removing tmp table   | 0.000007 |

| query end            | 0.000007 |

| closing tables       | 0.000015 |

| freeing items        | 0.000032 |

| cleaning up          | 0.000043 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

mysql>

mysql> set optimizer_search_depth=3;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 259;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000186 |

| checking permissions | 0.000014 |

| checking permissions | 0.000006 |

| checking permissions | 0.000006 |

| checking permissions | 0.000008 |

| Opening tables       | 0.000117 |

| init                 | 0.000058 |

| System lock          | 0.000034 |

| optimizing           | 0.000061 |

| statistics           | 0.000167 |

| preparing            | 0.000042 |

| Creating tmp table   | 0.000040 |

| Sorting result       | 0.000009 |

| explaining           | 0.000078 |

| query end            | 0.000014 |

| removing tmp table   | 0.000008 |

| query end            | 0.000004 |

| closing tables       | 0.000251 |

| freeing items        | 0.000050 |

| cleaning up          | 0.000024 |

+----------------------+----------+

20 rows in set, 1 warning (0.01 sec)

mysql>

mysql> set optimizer_search_depth=4;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 261;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000217 |

| checking permissions | 0.000013 |

| checking permissions | 0.000006 |

| checking permissions | 0.000005 |

| checking permissions | 0.000008 |

| Opening tables       | 0.000100 |

| init                 | 0.000054 |

| System lock          | 0.000060 |

| optimizing           | 0.000030 |

| statistics           | 0.000149 |

| preparing            | 0.000042 |

| Creating tmp table   | 0.000037 |

| Sorting result       | 0.000009 |

| explaining           | 0.000076 |

| query end            | 0.000014 |

| removing tmp table   | 0.000008 |

| query end            | 0.000007 |

| closing tables       | 0.000014 |

| freeing items        | 0.000048 |

| cleaning up          | 0.000041 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

mysql> set optimizer_search_depth=5;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 263;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000175 |

| checking permissions | 0.000035 |

| checking permissions | 0.000010 |

| checking permissions | 0.000006 |

| checking permissions | 0.000022 |

| Opening tables       | 0.000118 |

| init                 | 0.000084 |

| System lock          | 0.000056 |

| optimizing           | 0.000033 |

| statistics           | 0.000130 |

| preparing            | 0.000038 |

| Creating tmp table   | 0.000060 |

| Sorting result       | 0.000010 |

| explaining           | 0.000078 |

| query end            | 0.000014 |

| removing tmp table   | 0.000007 |

| query end            | 0.000006 |

| closing tables       | 0.000014 |

| freeing items        | 0.000746 |

| cleaning up          | 0.000059 |

+----------------------+----------+

20 rows in set, 1 warning (0.01 sec)

mysql>

mysql> set optimizer_search_depth=6;

Query OK, 0 rows affected (0.00 sec)

mysql> explain extended select a.genre,count(*) from movies a join genre b on b.gen_id=a.genre join standard_menu c on b.gen_id=c.genre_id join menu_movie d where b.gen_id <1000000 and a.id=d.movie_id  and c.id=d.menu_code group by a.genre having count(*)>10 order by a.id desc;

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

| id | select_type | table | type   | possible_keys            | key              | key_len | ref                   | rows | filtered | Extra                                               |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

|  1 | SIMPLE      | d     | ALL    | menu_movie_menu_code_idx | NULL             | NULL    | NULL                  |  998 |   100.00 | Using where; Using temporary; Using filesort        |

|  1 | SIMPLE      | c     | eq_ref | PRIMARY,ind_genre_id     | PRIMARY          | 66      | Portal_19.d.menu_code |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

|  1 | SIMPLE      | b     | ref    | genre_gen_id_idx         | genre_gen_id_idx | 9       | Portal_19.c.genre_id  |    1 |   100.00 | Using where; Using index                            |

|  1 | SIMPLE      | a     | eq_ref | PRIMARY,genre_index      | PRIMARY          | 4       | Portal_19.d.movie_id  |    1 |   100.00 | Using where; Using join buffer (Batched Key Access) |

+----+-------------+-------+--------+--------------------------+------------------+---------+-----------------------+------+----------+-----------------------------------------------------+

4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 265;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000181 |

| checking permissions | 0.000013 |

| checking permissions | 0.000009 |

| checking permissions | 0.000006 |

| checking permissions | 0.000008 |

| Opening tables       | 0.000126 |

| init                 | 0.000054 |

| System lock          | 0.000033 |

| optimizing           | 0.000028 |

| statistics           | 0.000200 |

| preparing            | 0.000040 |

| Creating tmp table   | 0.000034 |

| Sorting result       | 0.000008 |

| explaining           | 0.000072 |

| query end            | 0.000013 |

| removing tmp table   | 0.000007 |

| query end            | 0.000006 |

| closing tables       | 0.000014 |

| freeing items        | 0.000996 |

| cleaning up          | 0.000078 |

+----------------------+----------+

20 rows in set, 1 warning (0.00 sec)

10.6总结及疑问

(1)官方文档说,如果optimizer_search_depth=0(If set to 0, the system automatically picks a reasonable value.),系统自动选择合理值,这个值怎么能查看到?

(2)可配置的参数optimizer_search_depth应该设置为多少才合适?不应少于join连接的表的个数?上述的测试在该值大于1时,似乎是最优的。

(3)思考:在执行一个多表join的时候,是否可以先定义一个预期,比如优化器决策join顺序的时间不能超过200ms。根据show profile for query n的值查看各执行环节的消耗时间从而做出判断?

(4)网上有人这样说:MySQL文档说明设置为0则表示能够自动选择optimizer_search_depth的合理值,实际上代码策略就是,如果join表数N<=7,则optimizer_search_depth=N+1,否则选N。没读过代码,真的是这样的吗?没测试出来,希望以后能够验证真假。

时间: 2024-10-14 20:04:03

optimizer_search_depth探讨的相关文章

Oracle12c多租户CDB 与 PDB 参数文件位置探讨、查询 CDB 与 PDB 不同值的参数

一. Oracle12c多租户CDB 与 PDB 参数文件位置 CDB的参数文件依然使用12c以前的SPIFLE,pdb的参数文件不会出现在SPFILE中,而是直接从CDB中继承,如果PDB中有privete Local parameter 会存在 CDB 的 PDB_SPFILE$字典表 中以con_id区别,当PDB UN-Plug时,PDB参数会写入PDB的XML文件中,当drop pluggable database后,pdb信息和PDB_SPFILE$记录也会被清除.再当PDB重新Pl

【算法整理】听说你写的算法很牛?-优质算法衡量标准探讨

引文 我有个朋友有算法强迫症,每次一看到别人写的算法,就有上去改的冲动,不然就会偏头疼,主要症结在于他认为别人写的算法不好,但是什么的算法可以评判为好,什么样的算法可以评判为不好?最近为了治愈他,我特地写了这篇文章. 算法的衡量从两个方向出发:时间复杂度和空间复杂度.本文主要是不讲具体算法,只将算法的衡量,重点讲解如何衡量算法的复杂度,解决平时见到的XX算法时间复杂是O(logn)O(logn),其中这个结果是怎么推导出来的?lognlogn是个什么玩意儿?,大写的OO是什么意思?为什么用这个符

面向数据可靠性存储系统设计思想探讨

存储系统的设计门槛是比较高的,和计算系统存在的最大区别在于存储系统所承载的是数据,一旦系统出现故障,不仅业务的连续性得不到保障,更为重要的是用户数据将会造成丢失.计算节点发生故障,最多造成业务连续性中断,这是与存储系统相比在可靠性要求方面最大的区别. 十几年前刚刚接触存储系统的研发,当时没有觉得存储有多复杂,不就是把数据按照一定规则存放在磁盘中,并且实现一定的功能,例如数据保护RAID.数据复制Replication.数据快照Snapshot以及文件系统嘛.感觉存储系统中最复杂的是各种功能,设计

六爻预测等各种预测术的本质探讨之随机数猜想

对于各类预测术,比如六爻术,源于周易八卦.大家对预测术的观点泾渭分明,要么很相信,要么很不屑.或者有些人认为信则有不信则无. 当然我本人是信奉现代科学的,不过预测术确实有不可思议的地方,对过去和未来的分析不是简单的一句"巧合,概率论"能说的过去的.现经过本人的一番分析,试图对各类预测术的本质来个大起底. 其实,预测术不神奇,更不是有什么鬼神之力.而且也不能说古人比现在人更聪明.预测术的外圈是遵循一定规律的一整套规则,这些规则是古代在不停的经验总结中逐步完善的.换句话说,只要你自己能遵循

云存储技术优势及其发展趋势的探讨

云存储技术优势及其发展趋势的探讨 1.引言 近年来,由于信息技术的发展,科学计算和商业计算等众多应用领域会产生了规模相当巨大的数据,并且数据量仍在快速增加,呈海量形式发展.在科学计算方面,如物理学.天文学.生物学等领域都会产生规模庞大的数据,而且每年的数据规模达到若干PB.而在商业计算方面,Web搜索.社会网络等需要处理的数据规模也非常庞大,例如,Google和Facebook等应用产生的数据达到PB甚至EB级.按照摩尔定律,处理器的速度每18个月就会翻一番,光纤技术的发展也大大加快了数据在网络

集团信息化之路 电子采购软件与现有库存及财务软件数据对接的探讨

多个单体软件的应用,肯定就会涉及到不同软件直接数据对接的问题.这次计划应用的电子采购系统也同样遇到了这个问题,在这夜里与大家共同探讨一下系统间数据对接的问题. 由于历史原因,原有应用的财务系统采用了分布式部署,各系统直接完全独立,虽然每天个站点也将数据上传到总部,但是并未进行集中汇总处理.更要紧的是原来各系统的编码甚至都不统一各自为政,前几年还特意进行了一次编码统一工作,将编码进行统一.但是后续编码的添加维护工作也很难完全做到一致. 由于当前没有统一集中的数据编码,因此进行不同系统间的接口开发也

Android IOS WebRTC 音视频开发总结(七六)-- 探讨直播低延迟低流量的粉丝连麦技术

本文主要探讨基于WebRTC的P2P直播粉丝连麦技术 (作者:郝飞,亲加云CTO,编辑:dora),最早发表在[这里] 支持原创,转载必须注明出处,欢迎关注微信公众号blacker(微信ID:blackerteam  或 webrtcorgcn) 到目前为止,直播行业继续如预期的那样如火如荼的发展着,在先后竞争完延迟,高清,美 颜,秒开等功能后,最近各大直播平台比拼的一个热点就是连麦.什么是连麦? 简单??述 就是当主播直播期间,可以与其中某一个粉丝进行互动,并且其他粉丝能够观看到这个互动 过程

C++ 中左值和右值的探讨

我的主力博客:半亩方塘 对于 C++ 中的左值和右值,我们通常的说法是:当一个对象被用作右值的时候,用的是对象的值(内容):当对象被用作左值的时候,用的是对象的身份(在内存中的位置),这句话来自于 <C++ Primer 第五版> 第 121 页,那么,对于这句话,该作何理解呢?下面我想来谈谈我的看法: ISO C++03规定表达式必须是左值或右值之一,而在ISO C++11中,左值性被正式地扩充为更复杂的值类别,对于一个变量来说,与它相关的有两个部分:一是变量在内存中的地址,二是这个变量在内

(转)从内存管 理、内存泄漏、内存回收探讨C++内存管理

http://www.cr173.com/html/18898_all.html 内存管理是C++最令人切齿痛恨的问题,也是C++最有争议的问题,C++高手从中获得了更好的性能,更大的自由,C++菜鸟的收获则是一遍一遍的检查代码和对 C++的痛恨,但内存管理在C++中无处不在,内存泄漏几乎在每个C++程序中都会发生,因此要想成为C++高手,内存管理一关是必须要过的,除非放弃 C++,转到Java或者.NET,他们的内存管理基本是自动的,当然你也放弃了自由和对内存的支配权,还放弃了C++超绝的性能