WL#12165: PERFORMANCE_SCHEMA, CAPTURE QUERY_ID

Affects: Server-8.0   —   Status: Complete

In the statement instrumentation in the performance schema,
capture the QUERY_ID maintained by the SQL layer for a statement,
and print this as STATEMENT_ID in the events_statements tables.

This is needed to correlate:
- the data collected in the performance schema statement instrumentation
- the query in the SQL layer

Requirements
============

CURRENT-VERSION = 8.0.14
PREVIOUS-VERSION = 5.7 (major upgrade) and 8.0.13 (minor upgrade)

(1) Table performance_schema.events_statements_current structure.
-----------------------------------------------------------------

Func-Req (1.1): A fresh MySQL installation of CURRENT-VERSION must create the
table with the proper structure.

Func-Req (1.2): An upgrade from PREVIOUS-VERSION to CURRENT-VERSION must create
the table with the proper structure.

Func-Req (1.3): Column STATEMENT_ID read-only, by users with
the proper grants.

(2) Table performance_schema.events_statements_history structure.
-----------------------------------------------------------------

Func-Req (2.1): A fresh MySQL installation of CURRENT-VERSION must create the
table with the proper structure.

Func-Req (2.2): An upgrade from PREVIOUS-VERSION to CURRENT-VERSION must create
the table with the proper structure.

Func-Req (2.3): Column STATEMENT_ID read-only, by users with
the proper grants.

(3) Table performance_schema.events_statements_history_long structure.
----------------------------------------------------------------------

Func-Req (3.1): A fresh MySQL installation of CURRENT-VERSION must create the
table with the proper structure.

Func-Req (3.2): An upgrade from PREVIOUS-VERSION to CURRENT-VERSION must create
the table with the proper structure.

Func-Req (3.3): Column STATEMENT_ID read-only, by users with
the proper grants.
TABLE performance_schema.events_statements_current
==================================================

Schema changes
--------------

CREATE TABLE `events_statements_current` (
  `THREAD_ID` bigint(20) unsigned NOT NULL,
  `EVENT_ID` bigint(20) unsigned NOT NULL,
...
  `NESTING_EVENT_LEVEL` int(11) DEFAULT NULL,

New column:

  `STATEMENT_ID` bigint(20) unsigned DEFAULT NULL,

  PRIMARY KEY (`THREAD_ID`,`EVENT_ID`)
) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

Privileges
----------

Column STATEMENT_ID is read only.

Column STATEMENT_ID semantic
------------------------

The QUERY_ID maintained by the server in the SQL layer is captured,
and displayed in column STATEMENT_ID.

Note that, in the SQL layer, the query id is maintained as:
- a global counter
- incremented atomically

so as a result, column STATEMENT_ID is in practice a statement identifier,
unique for the server instance.

TABLE performance_schema.events_statements_history
==================================================

Likewise

TABLE performance_schema.events_statements_history_long
=======================================================

Likewise