WL#4876: Parse options before initializing mysys

Affects: Server-9.x   —   Status: Complete

In mysqld, mysys is initialized (my_init()) before options are parsed
(handle_options()).
Thus, options which should influence objects part of mysys, don't.
Example: --safe-mutex-deadlock-detector=0 disables mutex deadlock detection in
6.0; but this option is parsed after the pthread_mutex_init() calls of
my_init(). So, mutexes initialized by my_init() always do mutex deadlock
detection, the option doesn't influence them.

Performance Schema is also impacted

The performance schema needs to initialize the server in this order:

1) Parse options affecting the performance schema

Performance schema specific options.
====================================

--performance-schema-enabled={true|false}
--performance-schema-max-mutex-instruments=
--performance-schema-max-rwlock-instruments=
--performance-schema-max-cond-instruments=
--performance-schema-max-thread-instruments=
--performance-schema-max-table-instruments=
--performance-schema-max-file-instruments=
--performance-schema-max-mutex=
--performance-schema-max-rwlock=
--performance-schema-max-cond=
--performance-schema-max-thread=
--performance-schema-max-table=
--performance-schema-max-file=
--performance-schema-events-waits-history-size=
--performance-schema-events-waits-history-long-size=

2) Allocate internal buffers based on options parsed in 1),
and internally deploy the instrumentation in the server

3) Execute MYSQL_MUTEX_INIT, MYSQL_RWLOCK_INIT, MYSQL_COND_INIT,
MYSQL_OPEN, MYSQL_FOPEN and pthread_create in the server code only *after* 2),
to collect instrumentation data.

Because handle_options() happens too late currently, the performance schema
code is duplicating parsing of options from the command line (argc, argv) in main().

This code is a work around that only partially works:
- the server honor ./mysqld --performance-schema-xxx
- the server ignores --performance-schema-xxx in my.cnf, which is not user
friendly and leads to confusion.
Also, code is duplicated because of this.

The desired result is that handle_options() parses all arguments before
initializing any mutex, rwlock, condition, or starting any thread.