Skip to content

Commit d1f2732

Browse files
committed
Bug#20956599 CAN'T SET PERFORMANCE_SCHEMA=OFF IN 5.7
Before this fix, For a server compiled with performance schema support, when starting the server with the performance schema disabled at startup time, as in: performance_schema = OFF the server would fail to create performance_schema tables, which in turn causes the creation of views provided by sysschema to fail. The root cause is as follows: - during the server startup, the code detects that the performance schema is not initialized. - the variable load_perfschema_engine stays as false as a result - later, when loading the performance schema plugin, the plugin is loaded with the option PLUGIN_OFF (aka, not loaded) - during the database initialization in mysql_system_tables.sql, the scripts looks for entries in table information_schema.engines, and finds none, leading the script to assume the server is not compiled with performance schema support. - performance schema tables are not created during the install. - installation of the sysschema views fail. The fix is to simplify and streamline the entire process, which is too convoluted. In particular, - a server compiled with performance schema support always load the performance schema engine, now mandatory, regardless of the runtime configuration. - a server compiled with performance schema support always create the performance schema tables during install. The database layout of the installed product should depend only on build options (to compile with of without the performance schema), and never depend on runtime configurations options (to start the server with or without instrumentation) When the performance schema is not used during server startup, no data will be collected and no memory allocated, so there is no performance impact: there are no changes here. The only change is to always create performance schema tables when the server is compiled with performance schema support.
1 parent 2ffd9e3 commit d1f2732

File tree

8 files changed

+30
-67
lines changed

8 files changed

+30
-67
lines changed
-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
# Copyright (C) 2010 Sun Microsystems, Inc.
2-
# Use is subject to license terms
3-
#
4-
# This program is free software; you can redistribute it and/or modify
5-
# it under the terms of the GNU General Public License as published by
6-
# the Free Software Foundation; version 2 of the License.
7-
#
8-
# This program is distributed in the hope that it will be useful,
9-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11-
# GNU General Public License for more details.
12-
#
13-
# You should have received a copy of the GNU General Public License
14-
# along with this program; if not, write to the Free Software
15-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
161

172
if (!`SELECT count(*) FROM information_schema.engines WHERE
18-
(support = 'YES' OR support = 'DEFAULT') AND
193
engine = 'PERFORMANCE_SCHEMA'`){
204
skip Need performance schema compiled in;
215
}

mysql-test/suite/perfschema/r/start_server_off.result

+23-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ information_schema
44
mtr
55
mysql
66
performance_schema
7+
sys
78
test
89
select count(*) from performance_schema.performance_timers;
910
count(*)
@@ -95,16 +96,16 @@ select * from performance_schema.replication_applier_configuration;
9596
select * from performance_schema.replication_applier_status;
9697
select * from performance_schema.replication_applier_status_by_coordinator;
9798
select * from performance_schema.replication_applier_status_by_worker;
98-
select * from performance_schema.status_global;
99+
select * from performance_schema.global_status;
99100
select * from performance_schema.status_by_thread;
100101
select * from performance_schema.status_by_user;
101102
select * from performance_schema.status_by_host;
102103
select * from performance_schema.status_by_account;
103104
select * from performance_schema.session_status;
104-
select * from performance_schema.variables_global;
105+
select * from performance_schema.global_variables;
105106
select * from performance_schema.variables_by_thread;
106107
select * from performance_schema.session_variables;
107-
show variables like "performance_schema%";
108+
show global variables like "performance_schema%";
108109
Variable_name Value
109110
performance_schema OFF
110111
performance_schema_accounts_size 100
@@ -124,30 +125,37 @@ performance_schema_max_digest_length 1024
124125
performance_schema_max_file_classes 50
125126
performance_schema_max_file_handles 32768
126127
performance_schema_max_file_instances 10000
127-
performance_schema_max_memory_classes 250
128-
performance_schema_max_metadata_locks -1
128+
performance_schema_max_index_stat 5000
129+
performance_schema_max_memory_classes 320
130+
performance_schema_max_metadata_locks 10000
129131
performance_schema_max_mutex_classes 200
130132
performance_schema_max_mutex_instances 5000
133+
performance_schema_max_prepared_statements_instances 100
131134
performance_schema_max_program_instances 5000
132135
performance_schema_max_rwlock_classes 40
133136
performance_schema_max_rwlock_instances 5000
134137
performance_schema_max_socket_classes 10
135138
performance_schema_max_socket_instances 1000
139+
performance_schema_max_sql_text_length 1024
136140
performance_schema_max_stage_classes 150
137-
performance_schema_max_statement_classes 189
141+
performance_schema_max_statement_classes 191
138142
performance_schema_max_statement_stack 10
139143
performance_schema_max_table_handles 1000
140144
performance_schema_max_table_instances 500
145+
performance_schema_max_table_lock_stat 500
141146
performance_schema_max_thread_classes 50
142147
performance_schema_max_thread_instances 200
143-
performance_schema_max_transaction_classes 10
144148
performance_schema_session_connect_attrs_size 2048
145149
performance_schema_setup_actors_size 100
146150
performance_schema_setup_objects_size 100
147151
performance_schema_users_size 100
148152
show engine PERFORMANCE_SCHEMA status;
149-
show status like "performance_schema%";
150-
show status like "performance_schema%";
153+
show global status like "performance_schema%";
154+
select * from information_schema.engines
155+
where engine = "PERFORMANCE_SCHEMA";
156+
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
157+
PERFORMANCE_SCHEMA YES Performance Schema NO NO NO
158+
show global status like "performance_schema%";
151159
Variable_name Value
152160
Performance_schema_accounts_lost 0
153161
Performance_schema_cond_classes_lost 0
@@ -157,12 +165,14 @@ Performance_schema_file_classes_lost 0
157165
Performance_schema_file_handles_lost 0
158166
Performance_schema_file_instances_lost 0
159167
Performance_schema_hosts_lost 0
168+
Performance_schema_index_stat_lost 0
160169
Performance_schema_locker_lost 0
161170
Performance_schema_memory_classes_lost 0
162171
Performance_schema_metadata_lock_lost 0
163172
Performance_schema_mutex_classes_lost 0
164173
Performance_schema_mutex_instances_lost 0
165174
Performance_schema_nested_statement_lost 0
175+
Performance_schema_prepared_statements_lost 0
166176
Performance_schema_program_lost 0
167177
Performance_schema_rwlock_classes_lost 0
168178
Performance_schema_rwlock_instances_lost 0
@@ -173,30 +183,30 @@ Performance_schema_stage_classes_lost 0
173183
Performance_schema_statement_classes_lost 0
174184
Performance_schema_table_handles_lost 0
175185
Performance_schema_table_instances_lost 0
186+
Performance_schema_table_lock_stat_lost 0
176187
Performance_schema_thread_classes_lost 0
177188
Performance_schema_thread_instances_lost 0
178-
Performance_schema_transaction_classes_lost 0
179189
Performance_schema_users_lost 0
180190
select * from performance_schema.setup_consumers;
181191
NAME ENABLED
182192
select * from performance_schema.setup_instruments;
183193
NAME ENABLED TIMED
184194
select * from performance_schema.setup_actors;
185-
HOST USER ROLE
195+
HOST USER ROLE ENABLED HISTORY
186196
select * from performance_schema.setup_objects;
187197
OBJECT_TYPE OBJECT_SCHEMA OBJECT_NAME ENABLED TIMED
188198
select * from performance_schema.setup_timers;
189199
NAME TIMER_NAME
190200
insert into performance_schema.setup_objects values ('TABLE', 'myschema', 'myobject', 'YES', 'YES');
191201
ERROR HY000: Invalid performance_schema usage.
192-
insert into performance_schema.setup_actors values ('myhost', 'mysuser', 'myrole');
202+
insert into performance_schema.setup_actors values ('myhost', 'mysuser', 'myrole', 'YES', 'YES');
193203
ERROR HY000: Invalid performance_schema usage.
194204
select * from performance_schema.setup_objects;
195205
OBJECT_TYPE OBJECT_SCHEMA OBJECT_NAME ENABLED TIMED
196206
update performance_schema.setup_objects set OBJECT_NAME = 'myobject';
197207
delete from performance_schema.setup_objects;
198208
select * from performance_schema.setup_actors;
199-
HOST USER ROLE
209+
HOST USER ROLE ENABLED HISTORY
200210
update performance_schema.setup_actors set HOST = 'myhost';
201211
delete from performance_schema.setup_actors;
202212
truncate performance_schema.events_stages_history_long;

mysql-test/suite/perfschema/t/start_server_off.test

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
--source ../include/start_server_common.inc
77

8+
select * from information_schema.engines
9+
where engine = "PERFORMANCE_SCHEMA";
10+
811
# Expecting all off / zero
912
show global status like "performance_schema%";
1013

@@ -26,7 +29,7 @@ select * from performance_schema.setup_timers;
2629
insert into performance_schema.setup_objects values ('TABLE', 'myschema', 'myobject', 'YES', 'YES');
2730

2831
--error ER_WRONG_PERFSCHEMA_USAGE
29-
insert into performance_schema.setup_actors values ('myhost', 'mysuser', 'myrole');
32+
insert into performance_schema.setup_actors values ('myhost', 'mysuser', 'myrole', 'YES', 'YES');
3033

3134
# Expect SELECT, UPDATE, DELETE and TRUNCATE to affect 0 rows, but with
3235
# no error because the target row(s) will not be found

scripts/mysql_system_tables.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ DROP PREPARE stmt;
321321
-- if the server is built with performance schema
322322
--
323323

324-
set @have_pfs= (select count(engine) from information_schema.engines where engine='PERFORMANCE_SCHEMA' and support != 'NO');
324+
set @have_pfs= (select count(engine) from information_schema.engines where engine='PERFORMANCE_SCHEMA');
325325

326326
--
327327
-- TABLE COND_INSTANCES

sql/mysqld.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,6 @@ static int remaining_argc;
709709
/** Remaining command line arguments (arguments), filtered by handle_options().*/
710710
static char **remaining_argv;
711711

712-
bool load_perfschema_engine= false;
713-
714712
int orig_argc;
715713
char **orig_argv;
716714

@@ -4405,9 +4403,6 @@ int mysqld_main(int argc, char **argv)
44054403
adjust_related_options(&requested_open_files);
44064404

44074405
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
4408-
if (pfs_param.m_enabled)
4409-
load_perfschema_engine= true;
4410-
44114406
if (ho_error == 0)
44124407
{
44134408
if (pfs_param.m_enabled && !opt_help && !opt_bootstrap)
@@ -4850,7 +4845,7 @@ int mysqld_main(int argc, char **argv)
48504845
- the tables are not supposed to exist yet, bootstrap will create them
48514846
- a check would print spurious error messages
48524847
*/
4853-
if (! opt_bootstrap && load_perfschema_engine)
4848+
if (! opt_bootstrap)
48544849
check_performance_schema();
48554850
#endif
48564851

sql/mysqld.h

-2
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,6 @@ static inline int my_thread_set_THR_THD(THD *thd)
352352
return my_set_thread_local(THR_THD, thd);
353353
}
354354

355-
extern bool load_perfschema_engine;
356-
357355
#ifdef HAVE_PSI_INTERFACE
358356

359357
C_MODE_START

sql/sql_plugin.cc

-27
Original file line numberDiff line numberDiff line change
@@ -1410,33 +1410,6 @@ int plugin_init(int *argc, char **argv, int flags)
14101410
tmp.state= 0;
14111411
tmp.load_option= mandatory ? PLUGIN_FORCE : PLUGIN_ON;
14121412

1413-
/*
1414-
If the performance schema is compiled in,
1415-
treat the storage engine plugin as 'mandatory',
1416-
to suppress any plugin-level options such as '--performance-schema'.
1417-
This is specific to the performance schema, and is done on purpose:
1418-
the server-level option '--performance-schema' controls the overall
1419-
performance schema initialization, which consists of much more that
1420-
the underlying storage engine initialization.
1421-
See mysqld.cc, set_vars.cc.
1422-
Suppressing ways to interfere directly with the storage engine alone
1423-
prevents awkward situations where:
1424-
- the user wants the performance schema functionality, by using
1425-
'--enable-performance-schema' (the server option),
1426-
- yet disable explicitly a component needed for the functionality
1427-
to work, by using '--skip-performance-schema' (the plugin)
1428-
*/
1429-
if (!my_strcasecmp(&my_charset_latin1, plugin->name, "PERFORMANCE_SCHEMA"))
1430-
{
1431-
if (load_perfschema_engine)
1432-
tmp.load_option= PLUGIN_FORCE;
1433-
else
1434-
{
1435-
tmp.load_option= PLUGIN_OFF;
1436-
continue;
1437-
}
1438-
}
1439-
14401413
free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
14411414
if (test_plugin_options(&tmp_root, &tmp, argc, argv))
14421415
tmp.state= PLUGIN_IS_DISABLED;

storage/perfschema/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ table_replication_applier_status_by_worker.cc
269269
table_replication_group_member_stats.cc
270270
)
271271

272-
MYSQL_ADD_PLUGIN(perfschema ${PERFSCHEMA_SOURCES} STORAGE_ENGINE DEFAULT STATIC_ONLY NOT_FOR_EMBEDDED)
272+
MYSQL_ADD_PLUGIN(perfschema ${PERFSCHEMA_SOURCES} STORAGE_ENGINE MANDATORY STATIC_ONLY NOT_FOR_EMBEDDED)
273273
IF(WITH_PERFSCHEMA_STORAGE_ENGINE AND WITH_UNIT_TESTS)
274274
ENABLE_TESTING()
275275
ADD_SUBDIRECTORY(unittest)

0 commit comments

Comments
 (0)