1.3 What Is New in MySQL 8.0 (original) (raw)
- Data dictionary. MySQL now incorporates a transactional data dictionary that stores information about database objects. In previous MySQL releases, dictionary data was stored in metadata files and nontransactional tables. For more information, see Chapter 16, MySQL Data Dictionary.
- Atomic data definition statements (Atomic DDL). An atomic DDL statement combines the data dictionary updates, storage engine operations, and binary log writes associated with a DDL operation into a single, atomic transaction. For more information, seeSection 15.1.1, “Atomic Data Definition Statement Support”.
- Upgrade procedure. Previously, after installation of a new version of MySQL, the MySQL server automatically upgrades the data dictionary tables at the next startup, after which the DBA is expected to invoke mysql_upgrade manually to upgrade the system tables in the
mysql
schema, as well as objects in other schemas such as thesys
schema and user schemas.
As of MySQL 8.0.16, the server performs the tasks previously handled by mysql_upgrade. After installation of a new MySQL version, the server now automatically performs all necessary upgrade tasks at the next startup and is not dependent on the DBA invokingmysql_upgrade. In addition, the server updates the contents of the help tables (somethingmysql_upgrade did not do). A new--upgrade server option provides control over how the server performs automatic data dictionary and server upgrade operations. For more information, seeSection 3.4, “What the MySQL Upgrade Process Upgrades”. - Session Reuse. MySQL Server now supports SSL session reuse by default with a timeout setting to control how long the server maintains a session cache that establishes the period during which a client is permitted to request session reuse for new connections. All MySQL client programs support session reuse. For server-side and client-side configuration information, seeSection 8.3.5, “Reusing SSL Sessions”.
In addition, C applications now can use the C API capabilities to enable session reuse for encrypted connections (see SSL Session Reuse). - Security and account management. These enhancements were added to improve security and enable greater DBA flexibility in account management:
- MySQL Enterprise Audit now supports using thescheduler component to configure and execute a recurring task to flush the in-memory cache. For setup instructions, seeEnabling the Audit Log Flush Task.
- A new password-validation system variable permits the configuration and enforcement of a minimum number of characters that users must change when attempting to replace their own MySQL account passwords. This new verification setting is a percentage of the total characters in the current password. For example, ifvalidate_password.changed_characters_percentage has a value of 50, at least half of the characters in the replacement account password must not be present in the current password, or the password is rejected. For more information, seeSection 8.4.3, “The Password Validation Component”.
- MySQL Enterprise Edition now provides data masking and de-identification capabilities based on components, rather than being based on a plugin library that was introduced in MySQL 8.0.13. MySQL Enterprise Data Masking and De-Identification components support for multibyte characters, masking dictionaries stored in a database table, and several new functions. For more information, see Section 8.5.1, “Data-Masking Components Versus the Data-Masking Plugin”.
- Prior to MySQL 8.0.33, the
mysql
system database was used for MySQL Enterprise Audit's persistent storage of filter and user account data. For enhanced flexibility, the newaudit_log_database server system variable now permits specifying other databases in the global schema namespace at server startup. Themysql
system database is the default setting for table storage. - The grant tables in the
mysql
system database are nowInnoDB
(transactional) tables. Previously, these wereMyISAM
(nontransactional) tables. The change of grant table storage engine underlies an accompanying change to the behavior of account-management statements. Previously, an account-management statement (such asCREATE USER orDROP USER) that named multiple users could succeed for some users and fail for others. Now, each statement is transactional and either succeeds for all named users or rolls back and has no effect if any error occurs. The statement is written to the binary log if it succeeds, but not if it fails; in that case, rollback occurs and no changes are made. For more information, see Section 15.1.1, “Atomic Data Definition Statement Support”. - A new
caching_sha2_password
authentication plugin is available. Like thesha256_password
plugin,caching_sha2_password
implements SHA-256 password hashing, but uses caching to address latency issues at connect time. It also supports more transport protocols and does not require linking against OpenSSL for RSA key pair-based password-exchange capabilities. SeeSection 8.4.1.2, “Caching SHA-2 Pluggable Authentication”.
Thecaching_sha2_password
andsha256_password
authentication plugins provide more secure password encryption than themysql_native_password
plugin (deprecated in 8.0.34), andcaching_sha2_password
provides better performance thansha256_password
. Due to these superior security and performance characteristics ofcaching_sha2_password
, it is now the preferred authentication plugin, and is also the default authentication plugin rather thanmysql_native_password
. For information about the implications of this change of default plugin for server operation and compatibility of the server with clients and connectors, seecaching_sha2_password as the Preferred Authentication Plugin. - The MySQL Enterprise Edition SASL LDAP authentication plugin now supports GSSAPI/Kerberos as an authentication method for MySQL clients and servers on Linux. This is useful in Linux environments where applications access LDAP using Microsoft Active Directory, which has Kerberos enabled by default. SeeLDAP Authentication Methods.
- MySQL Enterprise Edition now supports an authentication method that enables users to authenticate to MySQL Server using Kerberos, provided that appropriate Kerberos tickets are available or can be obtained. For details, seeSection 8.4.1.8, “Kerberos Pluggable Authentication”.
- MySQL now supports roles, which are named collections of privileges. Roles can be created and dropped. Roles can have privileges granted to and revoked from them. Roles can be granted to and revoked from user accounts. The active applicable roles for an account can be selected from among those granted to the account, and can be changed during sessions for that account. For more information, see Section 8.2.10, “Using Roles”.
- MySQL now incorporates the concept of user account categories, with system and regular users distinguished according to whether they have theSYSTEM_USER privilege. See Section 8.2.11, “Account Categories”.
- Previously, it was not possible to grant privileges that apply globally except for certain schemas. This is now possible if thepartial_revokes system variable is enabled. SeeSection 8.2.12, “Privilege Restriction Using Partial Revokes”.
- The GRANT statement has an
AS _`user`_ [WITH ROLE]
clause that specifies additional information about the privilege context to use for statement execution. This syntax is visible at the SQL level, although its primary purpose is to enable uniform replication across all nodes of grantor privilege restrictions imposed by partial revokes, by causing those restrictions to appear in the binary log. SeeSection 15.7.1.6, “GRANT Statement”. - MySQL now maintains information about password history, enabling restrictions on reuse of previous passwords. DBAs can require that new passwords not be selected from previous passwords for some number of password changes or period of time. It is possible to establish password-reuse policy globally as well as on a per-account basis.
It is now possible to require that attempts to change account passwords be verified by specifying the current password to be replaced. This enables DBAs to prevent users from changing password without proving that they know the current password. It is possible to establish password-verification policy globally as well as on a per-account basis.
Accounts are now permitted to have dual passwords, which enables phased password changes to be performed seamlessly in complex multiple-server systems, without downtime.
MySQL now enables administrators to configure user accounts such that too many consecutive login failures due to incorrect passwords cause temporary account locking. The required number of failures and the lock time are configurable per account.
These new capabilities provide DBAs more complete control over password management. For more information, see Section 8.2.15, “Password Management”. - MySQL now supports FIPS mode, if compiled using OpenSSL, and an OpenSSL library and FIPS Object Module are available at runtime. FIPS mode imposes conditions on cryptographic operations such as restrictions on acceptable encryption algorithms or requirements for longer key lengths. See Section 8.8, “FIPS Support”.
- The TLS context the server uses for new connections now is reconfigurable at runtime. This capability may be useful, for example, to avoid restarting a MySQL server that has been running so long that its SSL certificate has expired. SeeServer-Side Runtime Configuration and Monitoring for Encrypted Connections.
- OpenSSL 1.1.1 supports the TLS v1.3 protocol for encrypted connections, and MySQL 8.0.16 and higher supports TLS v1.3 as well, if both the server and client are compiled using OpenSSL 1.1.1 or higher. SeeSection 8.3.2, “Encrypted Connection TLS Protocols and Ciphers”.
- MySQL now sets the access control granted to clients on the named pipe to the minimum necessary for successful communication on Windows. Newer MySQL client software can open named pipe connections without any additional configuration. If older client software cannot be upgraded immediately, the newnamed_pipe_full_access_group system variable can be used to give a Windows group the necessary permissions to open a named pipe connection. Membership in the full-access group should be restricted and temporary.
- Previously, MySQL user accounts authenticated to the server using a single authentication method. As of MySQL 8.0.27, MySQL supports multifactor authentication (MFA), which makes it possible to create accounts that have up to three authentication methods. MFA support entails these changes:
* CREATE USER andALTER USER syntax has been extended to permit specification of multiple authentication methods.
* Theauthentication_policy system variable enables MFA policy to be established by controlling how many factors can be used and the types of authentication permitted for each factor. This places constraints on how the authentication-related clauses ofCREATE USER andALTER USER statements may be used.
* Client programs have new--password1,--password2, and--password3 command-line options for specifying multiple passwords. For applications that use the C API, the newMYSQL_OPT_USER_PASSWORD
option for themysql_options4() C API function enables the same capability.
In addition, MySQL Enterprise Edition now supports authentication to MySQL Server using devices such as smart cards, security keys, and biometric readers. This authentication method is based on the Fast Identity Online (FIDO) standard, and uses a pair of plugins,
authentication_fido
on the server side andauthentication_fido_client
on the client side. The server-side FIDO authentication plugin is included only in MySQL Enterprise Edition distributions. It is not included in MySQL community distributions. However, the client-side plugin is included in all distributions, including community distributions. This enables clients from any distribution to connect to a server that has the server-side plugin loaded.
Multifactor authentication can use existing MySQL authentication methods, the new FIDO authentication method, or a combination of both. For more information, see Section 8.2.18, “Multifactor Authentication”, andSection 8.4.1.11, “FIDO Pluggable Authentication”. - Resource management. MySQL now supports creation and management of resource groups, and permits assigning threads running within the server to particular groups so that threads execute according to the resources available to the group. Group attributes enable control over its resources, to enable or restrict resource consumption by threads in the group. DBAs can modify these attributes as appropriate for different workloads. Currently, CPU time is a manageable resource, represented by the concept of “virtual CPU” as a term that includes CPU cores, hyperthreads, hardware threads, and so forth. The server determines at startup how many virtual CPUs are available, and database administrators with appropriate privileges can associate these CPUs with resource groups and assign threads to groups. For more information, seeSection 7.1.16, “Resource Groups”.
- Table encryption management. Table encryption can now be managed globally by defining and enforcing encryption defaults. Thedefault_table_encryption variable defines an encryption default for newly created schemas and general tablespace. The encryption default for a schema can also be defined using the
DEFAULT ENCRYPTION
clause when creating a schema. By default, a table inherits the encryption of the schema or general tablespace it is created in. Encryption defaults are enforced by enabling thetable_encryption_privilege_check variable. The privilege check occurs when creating or altering a schema or general tablespace with an encryption setting that differs from thedefault_table_encryption setting, or when creating or altering a table with an encryption setting that differs from the default schema encryption. TheTABLE_ENCRYPTION_ADMIN privilege permits overriding default encryption settings whentable_encryption_privilege_check is enabled. For more information, seeDefining an Encryption Default for Schemas and General Tablespaces. - InnoDB enhancements. These
InnoDB
enhancements were added:- The current maximum auto-increment counter value is written to the redo log each time the value changes, and saved to an engine-private system table on each checkpoint. These changes make the current maximum auto-increment counter value persistent across server restarts. Additionally:
* A server restart no longer cancels the effect of theAUTO_INCREMENT = N
table option. If you initialize the auto-increment counter to a specific value, or if you alter the auto-increment counter value to a larger value, the new value is persisted across server restarts.
* A server restart immediately following aROLLBACK operation no longer results in the reuse of auto-increment values that were allocated to the rolled-back transaction.
* If you modify anAUTO_INCREMENT
column value to a value larger than the current maximum auto-increment value (in anUPDATE operation, for example), the new value is persisted, and subsequentINSERT operations allocate auto-increment values starting from the new, larger value.
For more information, seeSection 17.6.1.6, “AUTO_INCREMENT Handling in InnoDB”, andInnoDB AUTO_INCREMENT Counter Initialization.
- When encountering index tree corruption,
InnoDB
writes a corruption flag to the redo log, which makes the corruption flag crash safe.InnoDB
also writes in-memory corruption flag data to an engine-private system table on each checkpoint. During recovery,InnoDB
reads corruption flags from both locations and merges results before marking in-memory table and index objects as corrupt. - The
InnoDB
memcached plugin supports multipleget
operations (fetching multiple key-value pairs in a single memcached query) and range queries. SeeSection 17.20.4, “InnoDB memcached Multiple get and Range Query Support”. - A new dynamic variable,innodb_deadlock_detect, may be used to disable deadlock detection. On high concurrency systems, deadlock detection can cause a slowdown when numerous threads wait for the same lock. At times, it may be more efficient to disable deadlock detection and rely on theinnodb_lock_wait_timeout setting for transaction rollback when a deadlock occurs.
- The new Information SchemaINNODB_CACHED_INDEXES table reports the number of index pages cached in the
InnoDB
buffer pool for each index. InnoDB
temporary tables are now created in the shared temporary tablespace,ibtmp1
.- The
InnoDB
tablespace encryption feature supports encryption of redo log and undo log data. SeeRedo Log Encryption, andUndo Log Encryption. InnoDB
supportsNOWAIT
andSKIP LOCKED
options withSELECT ... FOR SHARE
andSELECT ... FOR UPDATE
locking read statements.NOWAIT
causes the statement to return immediately if a requested row is locked by another transaction.SKIP LOCKED
removes locked rows from the result set. SeeLocking Read Concurrency with NOWAIT and SKIP LOCKED.
SELECT ... FOR SHARE
replacesSELECT ... LOCK IN SHARE MODE
, butLOCK IN SHARE MODE
remains available for backward compatibility. The statements are equivalent. However,FOR UPDATE
andFOR SHARE
supportNOWAIT
,SKIP LOCKED
, andOF_`tblname`_
options. See Section 15.2.13, “SELECT Statement”.
OF_`tblname`_
applies locking queries to named tables.ADD PARTITION
,DROP PARTITION
,COALESCE PARTITION
,REORGANIZE PARTITION
, andREBUILD PARTITION
ALTER TABLE options are supported by native partitioning in-place APIs and may be used withALGORITHM={COPY|INPLACE}
andLOCK
clauses.
DROP PARTITION
withALGORITHM=INPLACE
deletes data stored in the partition and drops the partition. However,DROP PARTITION
withALGORITHM=COPY
orold_alter_table=ON rebuilds the partitioned table and attempts to move data from the dropped partition to another partition with a compatiblePARTITION ... VALUES
definition. Data that cannot be moved to another partition is deleted.- The
InnoDB
storage engine now uses the MySQL data dictionary rather than its own storage engine-specific data dictionary. For information about the data dictionary, seeChapter 16, MySQL Data Dictionary. mysql
system tables and data dictionary tables are now created in a singleInnoDB
tablespace file namedmysql.ibd
in the MySQL data directory. Previously, these tables were created in individualInnoDB
tablespace files in themysql
database directory.- The following undo tablespace changes are introduced in MySQL 8.0:
* By default, undo logs now reside in two undo tablespaces that are created when the MySQL instance is initialized. Undo logs are no longer created in the system tablespace.
* As of MySQL 8.0.14, additional undo tablespaces can be created in a chosen location at runtime usingCREATE UNDO TABLESPACE syntax.CREATE UNDO TABLESPACE tablespace_name ADD DATAFILE 'file_name.ibu';
Undo tablespaces created usingCREATE UNDO TABLESPACE syntax can be dropped at runtime usingDROP UNDO TABLESPACE syntax.DROP UNDO TABLESPACE tablespace_name;
ALTER UNDO TABLESPACE syntax can be used to mark an undo tablespace as active or inactive.ALTER UNDO TABLESPACE tablespace_name SET {ACTIVE|INACTIVE};
ASTATE
column that shows the state of a tablespace was added to the Information SchemaINNODB_TABLESPACES table. An undo tablespace must be in anempty
state before it can be dropped.
* Theinnodb_undo_log_truncate variable is enabled by default.
* Theinnodb_rollback_segments variable defines the number of rollback segments per undo tablespace. Previously,innodb_rollback_segments specified the total number of rollback segments for the MySQL instance. This change increases the number of rollback segments available for concurrent transactions. More rollback segments increases the likelihood that concurrent transactions use separate rollback segments for undo logs, resulting in less resource contention. - Default values for variables that affect buffer pool preflushing and flushing behavior were modified:
* Theinnodb_max_dirty_pages_pct_lwm default value is now 10. The previous default value of 0 disables buffer pool preflushing. A value of 10 enables preflushing when the percentage of dirty pages in the buffer pool exceeds 10%. Enabling preflushing improves performance consistency.
* Theinnodb_max_dirty_pages_pct default value was increased from 75 to 90.InnoDB
attempts to flush data from the buffer pool so that the percentage of dirty pages does not exceed this value. The increased default value permits a greater percentage of dirty pages in the buffer pool. - The defaultinnodb_autoinc_lock_mode setting is now 2 (interleaved). Interleaved lock mode permits the execution of multi-row inserts in parallel, which improves concurrency and scalability. The newinnodb_autoinc_lock_mode default setting reflects the change from statement-based replication to row based replication as the default replication type in MySQL 5.7. Statement-based replication requires the consecutive auto-increment lock mode (the previous default) to ensure that auto-increment values are assigned in a predictable and repeatable order for a given sequence of SQL statements, whereas row-based replication is not sensitive to the execution order of SQL statements. For more information, seeInnoDB AUTO_INCREMENT Lock Modes.
For systems that use statement-based replication, the newinnodb_autoinc_lock_mode default setting may break applications that depend on sequential auto-increment values. To restore the previous default, setinnodb_autoinc_lock_mode to 1. - Renaming a general tablespace is supported byALTER TABLESPACE ... RENAME TO syntax.
- The--innodb-dedicated-server server option, which is disabled by default, can be used to have
InnoDB
automatically set values the following system variables according to the amount of memory detected on the server:
* innodb_buffer_pool_size
* innodb_log_file_size
* innodb_flush_method
This option is intended for MySQL server instances that run on a dedicated server. For more information, seeSection 17.8.12, “Enabling Automatic InnoDB Configuration for a Dedicated MySQL Server”.
- The new Information SchemaINNODB_TABLESPACES_BRIEF view provides space, name, path, flag, and space type data for
InnoDB
tablespaces. - The zlib library version bundled with MySQL was raised from version 1.2.3 to version 1.2.11. MySQL implements compression with the help of the zlib library.
If you useInnoDB
compressed tables, see Section 3.5, “Changes in MySQL 8.0” for related upgrade implications. - Serialized dictionary information (SDI) is present in all
InnoDB
tablespace files except for global temporary tablespace and undo tablespace files. SDI is serialized metadata for table and tablespace objects. The presence of SDI data provides metadata redundancy. For example, dictionary object metadata may be extracted from tablespace files if the data dictionary becomes unavailable. SDI extraction is performed using the ibd2sdi tool. SDI data is stored inJSON
format.
The inclusion of SDI data in tablespace files increases tablespace file size. An SDI record requires a single index page, which is 16KB in size by default. However, SDI data is compressed when it is stored to reduce the storage footprint. - The
InnoDB
storage engine now supports atomic DDL, which ensures that DDL operations are either fully committed or rolled back, even if the server halts during the operation. For more information, see Section 15.1.1, “Atomic Data Definition Statement Support”. - Tablespace files can be moved or restored to a new location while the server is offline using theinnodb_directories option. For more information, seeSection 17.6.3.6, “Moving Tablespace Files While the Server is Offline”.
- The following redo logging optimizations were implemented:
* User threads can now write concurrently to the log buffer without synchronizing writes.
* User threads can now add dirty pages to the flush list in a relaxed order.
* A dedicated log thread is now responsible for writing the log buffer to the system buffers, flushing system buffers to disk, notifying user threads about written and flushed redo, maintaining the lag required for the relaxed flush list order, and write checkpoints.
* System variables were added for configuring the use of spin delay by user threads waiting for flushed redo:
* innodb_log_wait_for_flush_spin_hwm: Defines the maximum average log flush time beyond which user threads no longer spin while waiting for flushed redo.
* innodb_log_spin_cpu_abs_lwm: Defines the minimum amount of CPU usage below which user threads no longer spin while waiting for flushed redo.
* innodb_log_spin_cpu_pct_hwm: Defines the maximum amount of CPU usage above which user threads no longer spin while waiting for flushed redo.
* Theinnodb_log_buffer_size variable is now dynamic, which permits resizing of the log buffer while the server is running.
For more information, seeSection 10.5.4, “Optimizing InnoDB Redo Logging”.
- As of MySQL 8.0.12, undo logging is supported for small updates to large object (LOB) data, which improves performance of LOB updates that are 100 bytes in size or less. Previously, LOB updates were a minimum of one LOB page in size, which is less than optimal for updates that might only modify a few bytes. This enhancement builds upon support added in MySQL 8.0.4 for partial update of LOB data.
- As of MySQL 8.0.12,
ALGORITHM=INSTANT
is supported for the followingALTER TABLE operations:
* Adding a column. This feature is also referred to as“InstantADD COLUMN
”. Limitations apply. SeeSection 17.12.1, “Online DDL Operations”.
* Adding or dropping a virtual column.
* Adding or dropping a column default value.
* Modifying the definition of anENUM orSET column.
* Changing the index type.
* Renaming a table.
Operations that support
ALGORITHM=INSTANT
only modify metadata in the data dictionary. No metadata locks are taken on the table, and table data is unaffected, making the operations instantaneous. If not specified explicitly,ALGORITHM=INSTANT
is used by default by operations that support it. IfALGORITHM=INSTANT
is specified but not supported, the operation fails immediately with an error.
For more information about operations that supportALGORITHM=INSTANT
, seeSection 17.12.1, “Online DDL Operations”.- As of MySQL 8.0.13, the
TempTable
storage engine supports storage of binary large object (BLOB) type columns. This enhancement improves performance for queries that use temporary tables containing BLOB data. Previously, temporary tables that contained BLOB data were stored in the on-disk storage engine defined byinternal_tmp_disk_storage_engine. For more information, seeSection 10.4.4, “Internal Temporary Table Use in MySQL”. - As of MySQL 8.0.13, the
InnoDB
data-at-rest encryption feature supports general tablespaces. Previously, only file-per-table tablespaces could be encrypted. To support encryption of general tablespaces, CREATE TABLESPACE and ALTER TABLESPACE syntax was extended to include anENCRYPTION
clause.
The Information SchemaINNODB_TABLESPACES table now includes anENCRYPTION
column that indicates whether or not a tablespace is encrypted.
Thestage/innodb/alter tablespace (encryption)
Performance Schema stage instrument was added to permit monitoring of general tablespace encryption operations. - Disabling the
innodb_buffer_pool_in_core_file
variable reduces the size of core files by excludingInnoDB
buffer pool pages. To use this variable, the core_file variable must be enabled and the operating system must support theMADV_DONTDUMP
non-POSIX extension tomadvise()
, which is supported in Linux 3.4 and later. For more information, see Section 17.8.3.7, “Excluding Buffer Pool Pages from Core Files”. - As of MySQL 8.0.13, user-created temporary tables and internal temporary tables created by the optimizer are stored in session temporary tablespaces that are allocated to a session from a pool of temporary tablespaces. When a session disconnects, its temporary tablespaces are truncated and released back to the pool. In previous releases, temporary tables were created in the global temporary tablespace (
ibtmp1
), which did not return disk space to the operating system after temporary tables were dropped.
Theinnodb_temp_tablespaces_dir variable defines the location where session temporary tablespaces are created. The default location is the#innodb_temp
directory in the data directory.
TheINNODB_SESSION_TEMP_TABLESPACES table provides metadata about session temporary tablespaces.
The global temporary tablespace (ibtmp1
) now stores rollback segments for changes made to user-created temporary tables. - As of MySQL 8.0.14,
InnoDB
supports parallel clustered index reads, which can improveCHECK TABLE performance. This feature does not apply to secondary index scans. Theinnodb_parallel_read_threads session variable must be set to a value greater than 1 for parallel clustered index reads to occur. The default value is 4. The actual number of threads used to perform a parallel clustered index read is determined by theinnodb_parallel_read_threads setting or the number of index subtrees to scan, whichever is smaller. - As of 8.0.14, when the server is started with--innodb-dedicated-server, the size and number of log files are configured according to the automatically configured buffer pool size. Previously, log file size was configured according to the amount of memory detected on the server, and the number of log files was not configured automatically.
- As of 8.0.14, the
ADD DATAFILE
clause of the CREATE TABLESPACE statement is optional, which permits users without theFILE privilege to create tablespaces. A CREATE TABLESPACE statement executed without anADD DATAFILE
clause implicitly creates a tablespace data file with a unique file name. - By default, when the amount of memory occupied by the TempTable storage engine exceeds the memory limit defined by thetemptable_max_ram variable, the TempTable storage engine begins allocating memory-mapped temporary files from disk. As of MySQL 8.0.16, this behavior is controlled by thetemptable_use_mmap variable. Disablingtemptable_use_mmap causes the TempTable storage engine to use
InnoDB
on-disk internal temporary tables instead of memory-mapped files as its overflow mechanism. For more information, seeInternal Temporary Table Storage Engine. - As of MySQL 8.0.16, the
InnoDB
data-at-rest encryption feature supports encryption of themysql
system tablespace. Themysql
system tablespace contains themysql
system database and the MySQL data dictionary tables. For more information, seeSection 17.13, “InnoDB Data-at-Rest Encryption”. - Theinnodb_spin_wait_pause_multiplier variable, introduced in MySQL 8.0.16, provides greater control over the duration of spin-lock polling delays that occur when a thread waits to acquire a mutex or rw-lock. Delays can be tuned more finely to account for differences in PAUSE instruction duration on different processor architectures. For more information, seeSection 17.8.8, “Configuring Spin Lock Polling”.
InnoDB
parallel read thread performance for large data sets was improved in MySQL 8.0.17 through better utilization of read threads, through a reduction in read thread I/O for prefetch activity that occurs during parallel scans, and through support for parallel scanning of partitions.
The parallel read thread feature is controlled by theinnodb_parallel_read_threads variable. The maximum setting is now 256, which is the total number of threads for all client connections. If the thread limit is reached, connections fall back to using a single thread.- Theinnodb_idle_flush_pct variable, introduced in MySQL 8.0.18, permits placing a limit on page flushing during idle periods, which can help extend the life of solid state storage devices. SeeLimiting Buffer Flushing During Idle Periods.
- Efficient sampling of
InnoDB
data for the purpose of generating histogram statistics is supported as of MySQL 8.0.19. SeeHistogram Statistics Analysis. - As of MySQL 8.0.20, the doublewrite buffer storage area resides in doublewrite files. In previous releases, the storage area resided in the system tablespace. Moving the storage area out of the system tablespace reduces write latency, increases throughput, and provides flexibility with respect to placement of doublewrite buffer pages. The following system variables were introduced for advanced doublewrite buffer configuration:
* innodb_doublewrite_dir
Defines the doublewrite buffer file directory.
* innodb_doublewrite_files
Defines the number of doublewrite files.
* innodb_doublewrite_pages
Defines the maximum number of doublewrite pages per thread for a batch write.
* innodb_doublewrite_batch_size
Defines the number of doublewrite pages to write in a batch.
For more information, seeSection 17.6.4, “Doublewrite Buffer”.
- The Contention-Aware Transaction Scheduling (CATS) algorithm, which prioritizes transactions that are waiting for locks, was improved in MySQL 8.0.20. Transaction scheduling weight computation is now performed a separate thread entirely, which improves computation performance and accuracy.
The First In First Out (FIFO) algorithm, which had also been used for transaction scheduling, was removed. The FIFO algorithm was rendered redundant by CATS algorithm enhancements. Transaction scheduling previously performed by the FIFO algorithm is now performed by the CATS algorithm.
ATRX_SCHEDULE_WEIGHT
column was added to theINFORMATION_SCHEMA.INNODB_TRX
table, which permits querying transaction scheduling weights assigned by the CATS algorithm.
The followingINNODB_METRICS
counters were added for monitoring code-level transaction scheduling events:
*lock_rec_release_attempts
The number of attempts to release record locks.
*lock_rec_grant_attempts
The number of attempts to grant record locks.
*lock_schedule_refreshes
The number of times the wait-for graph was analyzed to update transaction schedule weights.
For more information, seeSection 17.7.6, “Transaction Scheduling”.
- As of MySQL 8.0.21, to improve concurrency for operations that require access to lock queues for table and row resources, the lock system mutex (
lock_sys->mutex
) was replaced in by sharded latches, and lock queues were grouped into table and page lock queue shards, with each shard protected by a dedicated mutex. Previously, the single lock system mutex protected all lock queues, which was a point of contention on high-concurrency systems. The new sharded implementation permits more granular access to lock queues.
The lock system mutex (lock_sys->mutex
) was replaced by the following sharded latches:
* A global latch (lock_sys->latches.global_latch
) consisting of 64 read-write lock objects (rw_lock_t
). Access to an individual lock queue requires a shared global latch and a latch on the lock queue shard. Operations that require access to all lock queues take an exclusive global latch, which latches all table and page lock queue shards.
* Table shard latches (lock_sys->latches.table_shards.mutexes
), implemented as an array of 512 mutexes, with each mutex dedicated to one of 512 table lock queue shards.
* Page shard latches (lock_sys->latches.page_shards.mutexes
), implemented as an array of 512 mutexes, with each mutex dedicated to one of 512 page lock queue shards.
The Performance Schema
wait/synch/mutex/innodb/lock_mutex
instrument for monitoring the single lock system mutex was replaced by instruments for monitoring the new global, table shard, and page shard latches:
*wait/synch/sxlock/innodb/lock_sys_global_rw_lock
*wait/synch/mutex/innodb/lock_sys_table_mutex
*wait/synch/mutex/innodb/lock_sys_page_mutex
- As of MySQL 8.0.21, table and table partition data files created outside of the data directory using the
DATA DIRECTORY
clause are restricted to directories known toInnoDB
. This change permits database administrators to control where tablespace data files are created and ensures that the data files can be found during recovery.
General and file-per-table tablespaces data files (.ibd
files) can no longer be created in the undo tablespace directory (innodb_undo_directory) unless that directly is known toInnoDB
.
Known directories are those defined by thedatadir,innodb_data_home_dir, and innodb_directories variables.
Truncating anInnoDB
table that resides in a file-per-table tablespace drops the existing tablespace and creates a new one. As of MySQL 8.0.21,InnoDB
creates the new tablespace in the default location and writes a warning to the error log if the current tablespace directory is unknown. To have TRUNCATE TABLE create the tablespace in its current location, add the directory to theinnodb_directories setting before running TRUNCATE TABLE. - As of MySQL 8.0.21, redo logging can be enabled and disabled usingALTER INSTANCE {ENABLE|DISABLE} INNODB REDO_LOG syntax. This functionality is intended for loading data into a new MySQL instance. Disabling redo logging helps speed up data loading by avoiding redo log writes.
The newINNODB_REDO_LOG_ENABLE privilege permits enabling and disabling redo logging.
The newInnodb_redo_log_enabled status variable permits monitoring redo logging status.
See Disabling Redo Logging. - At startup,
InnoDB
validates the paths of known tablespace files against tablespace file paths stored in the data dictionary in case tablespace files have been moved to a different location. The newinnodb_validate_tablespace_paths variable, introduced in MySQL 8.0.21, permits disabling tablespace path validation. This feature is intended for environments where tablespaces files are not moved. Disabling tablespace path validation improves startup time on systems with a large number of tablespace files.
For more information, seeSection 17.6.3.7, “Disabling Tablespace Path Validation”. - As of MySQL 8.0.21, on storage engines that support atomic DDL, theCREATE TABLE ... SELECT statement is logged as one transaction in the binary log when row-based replication is in use. Previously, it was logged as two transactions, one to create the table, and the other to insert data. With this change,CREATE TABLE ... SELECT statements are now safe for row-based replication and permitted for use with GTID-based replication. For more information, seeSection 15.1.1, “Atomic Data Definition Statement Support”.
- Truncating an undo tablespace on a busy system could affect performance due to associated flushing operations that remove old undo tablespace pages from the buffer pool and flush the initial pages of the new undo tablespace to disk. To address this issue, the flushing operations are removed as of MySQL 8.0.21.
Old undo tablespace pages are released passively as they become least recently used, or are removed at the next full checkpoint. The initial pages of the new undo tablespace are now redo logged instead of flushed to disk during the truncate operation, which also improves durability of the undo tablespace truncate operation.
To prevent potential issues caused by an excessive number of undo tablespace truncate operations, truncate operations on the same undo tablespace between checkpoints are now limited to 64. If the limit is exceeded, an undo tablespace can still be made inactive, but it is not truncated until after the next checkpoint.
INNODB_METRICS counters associated with defunct undo truncate flushing operations were removed. Removed counters include:undo_truncate_sweep_count
,undo_truncate_sweep_usec
,undo_truncate_flush_count
, andundo_truncate_flush_usec
.
See Section 17.6.3.4, “Undo Tablespaces”. - As of MySQL 8.0.22, the newinnodb_extend_and_initialize variable permits configuring how
InnoDB
allocates space to file-per-table and general tablespaces on Linux. By default, when an operation requires additional space in a tablespace,InnoDB
allocates pages to the tablespace and physically writes NULLs to those pages. This behavior affects performance if new pages are allocated frequently. You can disableinnodb_extend_and_initialize on Linux systems to avoid physically writing NULLs to newly allocated tablespace pages. Wheninnodb_extend_and_initialize is disabled, space is allocated usingposix_fallocate()
calls, which reserve space without physically writing NULLs.
Aposix_fallocate()
operation is not atomic, which makes it possible for a failure to occur between allocating space to a tablespace file and updating the file metadata. Such a failure can leave newly allocated pages in an uninitialized state, resulting in a failure whenInnoDB
attempts to access those pages. To prevent this scenario,InnoDB
writes a redo log record before allocating a new tablespace page. If a page allocation operation is interrupted, the operation is replayed from the redo log record during recovery. - As of MySQL 8.0.23,
InnoDB
supports encryption of doublewrite file pages belonging to encrypted tablespaces. The pages are encrypted using the encryption key of the associated tablespace. For more information, seeSection 17.13, “InnoDB Data-at-Rest Encryption”. - The temptable_max_mmap variable, introduced in MySQL 8.0.23, defines the maximum amount of memory the TempTable storage engine is permitted to allocate from memory-mapped (MMAP) files before it starts storing internal temporary table data on disk. A setting of 0 disables allocation from MMAP files. For more information, seeSection 10.4.4, “Internal Temporary Table Use in MySQL”.
- The
AUTOEXTEND_SIZE
option, introduced in MySQL 8.0.23, defines the amount by whichInnoDB
extends the size of a tablespace when it becomes full, making it possible to extend tablespace size in larger increments. TheAUTOEXTEND_SIZE
option is supported with the CREATE TABLE,ALTER TABLE,CREATE TABLESPACE, andALTER TABLESPACE statements. For more information, seeSection 17.6.3.9, “Tablespace AUTOEXTEND_SIZE Configuration”.
AnAUTOEXTEND_SIZE
size column was added to the Information SchemaINNODB_TABLESPACES table. - Theinnodb_segment_reserve_factor system variable, introduced in MySQL 8.0.26, permits configuring the percentage of tablespace file segment pages that are reserved as empty pages. For more information, seeConfiguring the Percentage of Reserved File Segment Pages.
- On platforms that support
fdatasync()
system calls, theinnodb_use_fdatasync variable, introduced in MySQL 8.0.26, permits usingfdatasync()
instead offsync()
for operating system flushes. Anfdatasync()
system call does not flush changes to file metadata unless required for subsequent data retrieval, providing a potential performance benefit. - As of MySQL 8.0.28, thetmp_table_size variable defines the maximum size of any individual in-memory internal temporary table created by the TempTable storage engine. An appropriate size limit prevents individual queries from consuming an inordinate amount global TempTable resources. SeeInternal Temporary Table Storage Engine.
- From MySQL 8.0.28, theinnodb_open_files variable, which defines the number of files
InnoDB
can have open at one time, can be set at runtime using aSELECT innodb_set_open_files_limit(_`N`_)
statement. The statement executes a stored procedure that sets the new limit.
To prevent non-LRU manged files from consuming the entireinnodb_open_files limit, non-LRU managed files are limited to 90 percent of theinnodb_open_files limit, which reserves 10 percent of theinnodb_open_files limit for LRU managed files.
The innodb_open_files limit includes temporary tablespace files, which were not counted toward the limit previously. - From MySQL 8.0.28,
InnoDB
supportsALTER TABLE ... RENAME COLUMN operations usingALGORITHM=INSTANT
.
For more information about this and other DDL operations that supportALGORITHM=INSTANT
, seeSection 17.12.1, “Online DDL Operations”. - From MySQL 8.0.29,
InnoDB
supportsALTER TABLE ... DROP COLUMN operations usingALGORITHM=INSTANT
.
Prior to MySQL 8.0.29, an instantly added column could only be added as the last column of the table. From MySQL 8.0.29, an instantly added column can be added to any position in the table.
Instantly added or dropped columns create a new version of the affected row. Up to 64 row versions are permitted. A newTOTAL_ROW_VERSIONS
column was added to the Information SchemaINNODB_TABLES table to track the number of row versions.
For more information about DDL operations that supportALGORITHM=INSTANT
, seeSection 17.12.1, “Online DDL Operations”. - From MySQL 8.0.30, theinnodb_doublewrite system variable supports
DETECT_ONLY
andDETECT_AND_RECOVER
settings. With theDETECT_ONLY
setting, database page content is not written to the doublewrite buffer, and recovery does not use the doublewrite buffer to fix incomplete page writes. This lightweight setting is intended for detecting incomplete page writes only. TheDETECT_AND_RECOVER
setting is equivalent to the existingON
setting. For more information, seeSection 17.6.4, “Doublewrite Buffer”. - From MySQL 8.0.30,
InnoDB
supports dynamic configuration of redo log capacity. Theinnodb_redo_log_capacity system variable can be set at runtime to increase or decrease the total amount of disk space occupied by redo log files.
With this change, the number of redo log files and their default location has also changed. From MySQL 8.0.30,InnoDB
maintains 32 redo log files in the#innodb_redo
directory in the data directory. Previously,InnoDB
created two redo log files in the data directory by default, and the number and size of redo log files were controlled by theinnodb_log_files_in_group andinnodb_log_file_size variables. These two variables are now deprecated.
When theinnodb_redo_log_capacity
setting is defined,innodb_log_files_in_group andinnodb_log_file_size settings are ignored; otherwise, those settings are used to compute theinnodb_redo_log_capacity
setting (innodb_log_files_in_group * innodb_log_file_size =innodb_redo_log_capacity
). If none of those variables are set, redo log capacity is set to theinnodb_redo_log_capacity
default value, which is 104857600 bytes (100MB).
Several status variables are provided for monitoring the redo log and redo log resizing operations.
For more information, seeSection 17.6.5, “Redo Log”. - With MySQL 8.0.31, there are two new status variables for monitoring online buffer pool resizing operations. TheInnodb_buffer_pool_resize_status_code status variable reports a status code indicating the stage of an online buffer pool resizing operation. TheInnodb_buffer_pool_resize_status_progress status variable reports a percentage value indicating the progress of each stage.
For more information, seeSection 17.8.3.1, “Configuring InnoDB Buffer Pool Size”.
- The current maximum auto-increment counter value is written to the redo log each time the value changes, and saved to an engine-private system table on each checkpoint. These changes make the current maximum auto-increment counter value persistent across server restarts. Additionally:
- Character set support. The default character set has changed from
latin1
toutf8mb4
. Theutf8mb4
character set has several new collations, includingutf8mb4_ja_0900_as_cs
, the first Japanese language-specific collation available for Unicode in MySQL. For more information, seeSection 12.10.1, “Unicode Character Sets”. - JSON enhancements. The following enhancements or additions were made to MySQL's JSON functionality:
- Added the->> (inline path) operator, which is equivalent to callingJSON_UNQUOTE() on the result of JSON_EXTRACT().
This is a refinement of the column path operator-> introduced in MySQL 5.7;col->>"$.path"
is equivalent toJSON_UNQUOTE(col->"$.path")
. The inline path operator can be used wherever you can useJSON_UNQUOTE(JSON_EXTRACT())
, suchSELECT column lists,WHERE
andHAVING
clauses, andORDER BY
andGROUP BY
clauses. For more information, see the description of the operator, as well as JSON Path Syntax. - Added two JSON aggregation functionsJSON_ARRAYAGG() andJSON_OBJECTAGG().
JSON_ARRAYAGG()
takes a column or expression as its argument, and aggregates the result as a single JSON array. The expression can evaluate to any MySQL data type; this does not have to be aJSON
value.JSON_OBJECTAGG()
takes two columns or expressions which it interprets as a key and a value; it returns the result as a singleJSON
object. For more information and examples, seeSection 14.19, “Aggregate Functions”. - Added the JSON utility functionJSON_PRETTY(), which outputs an existing JSON value in an easy-to-read format; each JSON object member or array value is printed on a separate line, and a child object or array is intended 2 spaces with respect to its parent.
This function also works with a string that can be parsed as a JSON value.
For more detailed information and examples, seeSection 14.17.8, “JSON Utility Functions”. - When sorting JSON values in a query using
ORDER BY
, each value is now represented by a variable-length part of the sort key, rather than a part of a fixed 1K in size. In many cases this can reduce excessive usage. For example, a scalarINT
or evenBIGINT
value actually requires very few bytes, so that the remainder of this space (up to 90% or more) was taken up by padding. This change has the following benefits for performance:
* Sort buffer space is now used more effectively, so that filesorts need not flush to disk as early or often as with fixed-length sort keys. This means that more data can be sorted in memory, avoiding unnecessary disk access.
* Shorter keys can be compared more quickly than longer ones, providing a noticeable improvement in performance. This is true for sorts performed entirely in memory as well as for sorts that require writing to and reading from disk. - Added support in MySQL 8.0.2 for partial, in-place updates of
JSON
column values, which is more efficient than completely removing an existing JSON value and writing a new one in its place, as was done previously when updating anyJSON
column. For this optimization to be applied, the update must be applied usingJSON_SET(),JSON_REPLACE(), orJSON_REMOVE(). New elements cannot be added to the JSON document being updated; values within the document cannot take more space than they did before the update. SeePartial Updates of JSON Values, for a detailed discussion of the requirements.
Partial updates of JSON documents can be written to the binary log, taking up less space than logging complete JSON documents. Partial updates are always logged as such when statement-based replication is in use. For this to work with row-based replication, you must first setbinlog_row_value_options=PARTIAL_JSON; see this variable's description for more information. - Added the JSON utility functionsJSON_STORAGE_SIZE() andJSON_STORAGE_FREE().
JSON_STORAGE_SIZE()
returns the storage space in bytes used for the binary representation of a JSON document prior to any partial update (see previous item).JSON_STORAGE_FREE()
shows the amount of space remaining in a table column of typeJSON after it has been partially updated usingJSON_SET()
orJSON_REPLACE()
; this is greater than zero if the binary representation of the new value is less than that of the previous value.
Each of these functions also accepts a valid string representation of a JSON document. For such a value,JSON_STORAGE_SIZE()
returns the space used by its binary representation following its conversion to a JSON document. For a variable containing the string representation of a JSON document,JSON_STORAGE_FREE()
returns zero. Either function produces an error if its (non-null) argument cannot be parsed as a valid JSON document, andNULL
if the argument isNULL
.
For more information and examples, seeSection 14.17.8, “JSON Utility Functions”.
JSON_STORAGE_SIZE()
andJSON_STORAGE_FREE()
were implemented in MySQL 8.0.2. - Added support in MySQL 8.0.2 for ranges such as
$[1 to 5]
in XPath expressions. Also added support in this version for thelast
keyword and relative addressing, such that$[last]
always selects the last (highest-numbered) element in the array and$[last-1]
the next to last element.last
and expressions using it can also be included in range definitions. For example,$[last-2 to last-1]
returns the last two elements but one from an array. SeeSearching and Modifying JSON Values, for additional information and examples. - Added a JSON merge function intended to conform toRFC 7396.JSON_MERGE_PATCH(), when used on 2 JSON objects, merges them into a single JSON object that has as members a union of the following sets:
* Each member of the first object for which there is no member with the same key in the second object.
* Each member of the second object for which there is no member having the same key in the first object, and whose value is not the JSONnull
literal.
* Each member having a key that exists in both objects, and whose value in the second object is not the JSONnull
literal.
As part of this work, theJSON_MERGE() function has been renamedJSON_MERGE_PRESERVE().
JSON_MERGE()
continues to be recognized as an alias forJSON_MERGE_PRESERVE()
in MySQL 8.0, but is now deprecated and is subject to removal in a future version of MySQL.
For more information and examples, seeSection 14.17.4, “Functions That Modify JSON Values”.- Implemented “last duplicate key wins” normalization of duplicate keys, consistent withRFC 7159 and most JavaScript parsers. An example of this behavior is shown here, where only the rightmost member having the key
x
is preserved:
mysql> SELECT JSON_OBJECT('x', '32', 'y', '[true, false]', > 'x', '"abc"', 'x', '100') AS Result; +------------------------------------+ | Result | +------------------------------------+ | {"x": "100", "y": "[true, false]"} | +------------------------------------+ 1 row in set (0.00 sec)
Values inserted into MySQLJSON columns are also normalized in this way, as shown in this example:
mysql> CREATE TABLE t1 (c1 JSON); mysql> INSERT INTO t1 VALUES ('{"x": 17, "x": "red", "x": [3, 5, 7]}'); mysql> SELECT c1 FROM t1; +------------------+ | c1 | +------------------+ | {"x": [3, 5, 7]} | +------------------+
This is an incompatible change from previous versions of MySQL, where a “first duplicate key wins” algorithm was used in such cases.
See Normalization, Merging, and Autowrapping of JSON Values, for more information and examples.- Added the JSON_TABLE() function in MySQL 8.0.4. This function accepts JSON data and returns it as a relational table having the specified columns.
This function has the syntaxJSON_TABLE(_`expr`_,_`path`_ COLUMNS_`columnlist`_) [AS]_`alias`_)
, where_expr
_ is an expression that returns JSON data,path
is a JSON path applied to the source, and_columnlist
_ is a list of column definitions. An example is shown here:
mysql> SELECT * -> FROM -> JSON_TABLE( -> '[{"a":3,"b":"0"},{"a":"3","b":"1"},{"a":2,"b":1},{"a":0},{"b":[1,2]}]', -> "$[*]" COLUMNS( -> rowid FOR ORDINALITY, -> -> xa INT EXISTS PATH "$.a", -> xb INT EXISTS PATH "$.b", -> -> sa VARCHAR(100) PATH "$.a", -> sb VARCHAR(100) PATH "$.b", -> -> ja JSON PATH "$.a", -> jb JSON PATH "$.b" -> ) -> ) AS jt1; +-------+------+------+------+------+------+--------+ | rowid | xa | xb | sa | sb | ja | jb | +-------+------+------+------+------+------+--------+ | 1 | 1 | 1 | 3 | 0 | 3 | "0" | | 2 | 1 | 1 | 3 | 1 | "3" | "1" | | 3 | 1 | 1 | 2 | 1 | 2 | 1 | | 4 | 1 | 0 | 0 | NULL | 0 | NULL | | 5 | 0 | 1 | NULL | NULL | NULL | [1, 2] | +-------+------+------+------+------+------+--------+
The JSON source expression can be any expression that yields a valid JSON document, including a JSON literal, a table column, or a function call that returns JSON such as JSON_EXTRACT(t1, data, '$.post.comments'). For more information, seeSection 14.17.6, “JSON Table Functions”.
- Added the->> (inline path) operator, which is equivalent to callingJSON_UNQUOTE() on the result of JSON_EXTRACT().
- Data type support. MySQL now supports use of expressions as default values in data type specifications. This includes the use of expressions as default values for theBLOB,TEXT,
GEOMETRY
, andJSON data types, which previously could not be assigned default values at all. For details, see Section 13.6, “Data Type Default Values”. - Optimizer. These optimizer enhancements were added:
- MySQL now supports invisible indexes. An invisible index is not used by the optimizer at all, but is otherwise maintained normally. Indexes are visible by default. Invisible indexes make it possible to test the effect of removing an index on query performance, without making a destructive change that must be undone should the index turn out to be required. SeeSection 10.3.12, “Invisible Indexes”.
- MySQL now supports descending indexes:
DESC
in an index definition is no longer ignored but causes storage of key values in descending order. Previously, indexes could be scanned in reverse order but at a performance penalty. A descending index can be scanned in forward order, which is more efficient. Descending indexes also make it possible for the optimizer to use multiple-column indexes when the most efficient scan order mixes ascending order for some columns and descending order for others. See Section 10.3.13, “Descending Indexes”. - MySQL now supports creation of functional index key parts that index expression values rather than column values. Functional key parts enable indexing of values that cannot be indexed otherwise, such asJSON values. For details, see Section 15.1.15, “CREATE INDEX Statement”.
- In MySQL 8.0.14 and later, trivial
WHERE
conditions arising from constant literal expressions are removed during preparation, rather than later on during optimization. Removal of the condition earlier in the process makes it possible to simplify joins for queries with outer joins having trivial conditions, such as this one:
SELECT * FROM t1 LEFT JOIN t2 ON condition_1 WHERE condition_2 OR 0 = 1
The optimizer now sees during preparation that 0 = 1 is always false, making
OR 0 = 1
redundant, and removes it, leaving this:SELECT * FROM t1 LEFT JOIN t2 ON condition_1 where condition_2
Now the optimizer can rewrite the query as an inner join, like this:
SELECT * FROM t1 LEFT JOIN t2 WHERE condition_1 AND condition_2
For more information, seeSection 10.2.1.9, “Outer Join Optimization”.
- In MySQL 8.0.16 and later, MySQL can use constant folding at optimization time to handle comparisons between a column and a constant value where the constant is out of range or on a range boundary with respect to the type of the column, rather than doing so for each row at execution time. For example, given a table
t
with aTINYINT UNSIGNED
columnc
, the optimizer can rewrite a condition such asWHERE c < 256
toWHERE 1
(and optimize the condition away altogether), orWHERE c >= 255
toWHERE c = 255
.
See Section 10.2.1.14, “Constant-Folding Optimization”, for more information. - Beginning with MySQL 8.0.16, the semijoin optimizations used with
IN
subqueries can now be applied toEXISTS
subqueries as well. In addition, the optimizer now decorrelates trivially-correlated equality predicates in theWHERE
condition attached to the subquery, so that they can be treated similarly to expressions inIN
subqueries; this applies to bothEXISTS
andIN
subqueries.
For more information, see Section 10.2.2.1, “Optimizing IN and EXISTS Subquery Predicates with Semijoin Transformations”. - As of MySQL 8.0.17, the server rewrites any incomplete SQL predicates (that is, predicates having the form
WHERE_`value`_
, in which_value
_ is a column name or constant expression and no comparison operator is used) internally asWHERE_`value`_ <> 0
during the contextualization phase, so that the query resolver, query optimizer, and query executor need work only with complete predicates.
One visible effect of this change is that, for Boolean values, EXPLAIN output now showstrue
andfalse
, rather than1
and0
.
Another effect of this change is that evaluation of a JSON value in an SQL boolean context performs an implicit comparison against JSON integer 0. Consider the table created and populated as shown here:
mysql> CREATE TABLE test (id INT, col JSON); mysql> INSERT INTO test VALUES (1, '{"val":true}'), (2, '{"val":false}');
Previously, the server attempted to convert an extracted
true
orfalse
value to an SQL boolean when comparing it in an SQL boolean context, as shown by the following query usingIS TRUE
:mysql> SELECT id, col, col->"$.val" FROM test WHERE col->"$.val" IS TRUE; +------+---------------+--------------+ | id | col | col->"$.val" | +------+---------------+--------------+ | 1 | {"val": true} | true | +------+---------------+--------------+
In MySQL 8.0.17 and later, the implicit comparison of the extracted value with JSON integer 0 leads to a different result:
mysql> SELECT id, col, col->"$.val" FROM test WHERE col->"$.val" IS TRUE; +------+----------------+--------------+ | id | col | col->"$.val" | +------+----------------+--------------+ | 1 | {"val": true} | true | | 2 | {"val": false} | false | +------+----------------+--------------+
Beginning with MySQL 8.0.21, you can useJSON_VALUE() on the extracted value to perform type conversion prior to performing the test, as shown here:
mysql> SELECT id, col, col->"$.val" FROM test -> WHERE JSON_VALUE(col, "$.val" RETURNING UNSIGNED) IS TRUE; +------+---------------+--------------+ | id | col | col->"$.val" | +------+---------------+--------------+ | 1 | {"val": true} | true | +------+---------------+--------------+
Also beginning with MySQL 8.0.21, the server provides the warning Evaluating a JSON value in SQL boolean context does an implicit comparison against JSON integer 0; if this is not what you want, consider converting JSON to an SQL numeric type with JSON_VALUE RETURNING when comparing extracted values in an SQL boolean context in this manner.
- In MySQL 8.0.17 and later a
WHERE
condition havingNOT IN (_`subquery`_)
orNOT EXISTS (_`subquery`_)
is transformed internally into an antijoin. (An antijoin returns all rows from the table for which there is no row in the table to which it is joined matching the join condition.) This removes the subquery which can result in faster query execution since the subquery's tables are now handled on the top level.
This is similar to, and reuses, the existingIS NULL
(Not exists
) optimization for outer joins; seeEXPLAIN Extra Information. - Beginning with MySQL 8.0.21, a single-tableUPDATE orDELETE statement can now in many cases make use of a semijoin transformation or subquery materialization. This applies to statements of the forms shown here:
*UPDATE t1 SET t1.a=_`value`_ WHERE t1.a IN (SELECT t2.a FROM t2)
*DELETE FROM t1 WHERE t1.a IN (SELECT t2.a FROM t2)
This can be done for a single-table
UPDATE
orDELETE
meeting the following conditions:
* TheUPDATE
orDELETE
statement uses a subquery having a[NOT] IN
or[NOT] EXISTS
predicate.
* The statement has noORDER BY
clause, and has noLIMIT
clause.
(The multi-table versions ofUPDATE
andDELETE
do not supportORDER BY
orLIMIT
.)
* The target table does not support read-before-write removal (relevant only forNDB tables).
* Semijoin or subquery materialization is allowed, based on any hints contained in the subquery and the value ofoptimizer_switch.
When the semijoin optimization is used for an eligible single-tableDELETE
orUPDATE
, this is visible in the optimizer trace: for a multi-table statement there is ajoin_optimization
object in the trace, while there is none for a single-table statement. The conversion is also visible in the output ofEXPLAIN FORMAT=TREE
orEXPLAIN ANALYZE; a single-table statement shows<not executable by iterator executor>
, while a multi-table statement reports a full plan.
Also beginning with MySQL 8.0.21, semi-consistent reads are supported by multi-tableUPDATE
statements using InnoDB tables, for transaction isolation levels weaker thanREPEATABLE READ.- Improved hash join performance. MySQL 8.0.23 reimplements the hash table used for hash joins, resulting in several improvements in hash join performance. This work includes a fix for an issue (Bug #31516149, Bug #99933) whereby only roughly 2/3 of the memory allocated for the join buffer (join_buffer_size) could actually be used by a hash join.
The new hash table is generally faster than the old one, and uses less memory for alignment, keys/values, and in scenarios where there are many equal keys. In addition, the server can now free old memory when the size of the hash table increases.
- Common table expressions. MySQL now supports common table expressions, both nonrecursive and recursive. Common table expressions enable use of named temporary result sets, implemented by permitting a WITH clause preceding SELECT statements and certain other statements. For more information, seeSection 15.2.20, “WITH (Common Table Expressions)”.
As of MySQL 8.0.19, the recursiveSELECT part of a recursive common table expression (CTE) supports aLIMIT
clause.LIMIT
withOFFSET
is also supported. SeeRecursive Common Table Expressions, for more information. - Window functions. MySQL now supports window functions that, for each row from a query, perform a calculation using rows related to that row. These include functions such asRANK(),LAG(), andNTILE(). In addition, several existing aggregate functions now can be used as window functions (for example,SUM() andAVG()). For more information, see Section 14.20, “Window Functions”.
- Lateral derived tables. A derived table now may be preceded by the
LATERAL
keyword to specify that it is permitted to refer to (depend on) columns of preceding tables in the sameFROM
clause. Lateral derived tables make possible certain SQL operations that cannot be done with nonlateral derived tables or that require less-efficient workarounds. SeeSection 15.2.15.9, “Lateral Derived Tables”. - Aliases in single-table DELETE statements. In MySQL 8.0.16 and later, single-tableDELETE statements support the use of table aliases.
- Regular expression support. Previously, MySQL used the Henry Spencer regular expression library to support regular expression operators (REGEXP,RLIKE). Regular expression support has been reimplemented using International Components for Unicode (ICU), which provides full Unicode support and is multibyte safe. TheREGEXP_LIKE() function performs regular expression matching in the manner of theREGEXP andRLIKE operators, which now are synonyms for that function. In addition, theREGEXP_INSTR(),REGEXP_REPLACE(), andREGEXP_SUBSTR() functions are available to find match positions and perform substring substitution and extraction, respectively. Theregexp_stack_limit andregexp_time_limit system variables provide control over resource consumption by the match engine. For more information, seeSection 14.8.2, “Regular Expressions”. For information about ways in which applications that use regular expressions may be affected by the implementation change, seeRegular Expression Compatibility Considerations.
One effect of this change is that[a-zA-Z]
and[0-9]
perform much better in MySQL 8.0 than[[:alpha:]]
and[[:digit:]]
, respectively. Existing applications that use the character classes in pattern matching should be upgraded to use the ranges instead. - Internal temporary tables. The
TempTable
storage engine replaces theMEMORY
storage engine as the default engine for in-memory internal temporary tables. TheTempTable
storage engine provides efficient storage forVARCHAR andVARBINARY columns. Theinternal_tmp_mem_storage_engine session variable defines the storage engine for in-memory internal temporary tables. Permitted values areTempTable
(the default) andMEMORY
. Thetemptable_max_ram variable defines the maximum amount of memory that theTempTable
storage engine can use before data is stored to disk. - Logging. These enhancements were added to improve logging:
- Error logging was rewritten to use the MySQL component architecture. Traditional error logging is implemented using built-in components, and logging using the system log is implemented as a loadable component. In addition, a loadable JSON log writer is available. For more information, see Section 7.4.2, “The Error Log”.
- From MySQL 8.0.30, error log components can be loaded implicitly at startup before the
InnoDB
storage engine is available. This new method of loading error log components loads and enables the components defined by thelog_error_services variable.
Previously, error log components had to be installed first using INSTALL COMPONENT and could only be loaded afterInnoDB
was fully available, as the list of components to load was read from themysql.components
table, which is anInnoDB
table.
Implicit loading of error log components has these advantages:
* Log components are loaded earlier in the startup sequence, making logged information available sooner.
* It helps avoid loss of buffered log information should a failure occur during startup.
* Loading log components usingINSTALL COMPONENT is not required, simplifying error log configuration.
The explicit method of loading log components using
INSTALL COMPONENT
remains supported for backward compatibility.
For more information, seeSection 7.4.2.1, “Error Log Configuration”. - Backup lock. A new type of backup lock permits DML during an online backup while preventing operations that could result in an inconsistent snapshot. The new backup lock is supported byLOCK INSTANCE FOR BACKUP andUNLOCK INSTANCE syntax. TheBACKUP_ADMIN privilege is required to use these statements.
- Replication. The following enhancements have been made to MySQL Replication:
- MySQL Replication now supports binary logging of partial updates to JSON documents using a compact binary format, saving space in the log over logging complete JSON documents. Such compact logging is done automatically when statement-based logging is in use, and can be enabled by setting the new
binlog_row_value_options
system variable toPARTIAL_JSON
. For more information, see Partial Updates of JSON Values, as well as the description ofbinlog_row_value_options.
- MySQL Replication now supports binary logging of partial updates to JSON documents using a compact binary format, saving space in the log over logging complete JSON documents. Such compact logging is done automatically when statement-based logging is in use, and can be enabled by setting the new
- Connection management. MySQL Server now permits a TCP/IP port to be configured specifically for administrative connections. This provides an alternative to the single administrative connection that is permitted on the network interfaces used for ordinary connections even whenmax_connections connections are already established. SeeSection 7.1.12.1, “Connection Interfaces”.
MySQL now provides more control over the use of compression to minimize the number of bytes sent over connections to the server. Previously, a given connection was either uncompressed or used thezlib
compression algorithm. Now, it is also possible to use thezstd
algorithm, and to select a compression level forzstd
connections. The permitted compression algorithms can be configured on the server side, as well as on the connection-origination side for connections by client programs and by servers participating in source/replica replication or Group Replication. For more information, seeSection 6.2.8, “Connection Compression Control”. - Configuration. The maximum permitted length of host names throughout MySQL has been raised to 255 ASCII characters, up from the previous limit of 60 characters. This applies to, for example, host name-related columns in the data dictionary,
mysql
system schema, Performance Schema,INFORMATION_SCHEMA
, andsys
schema; theMASTER_HOST
value for theCHANGE MASTER TO statement; theHost
column inSHOW PROCESSLIST statement output; host names in account names (such as used in account-management statements and inDEFINER
attributes); and host name-related command options and system variables.
Caveats:- The increase in permitted host name length can affect tables with indexes on host name columns. For example, tables in the
mysql
system schema that index host names now have an explicitROW_FORMAT
attribute ofDYNAMIC
to accommodate longer index values. - Some file name-valued configuration settings might be constructed based on the server host name. The permitted values are constrained by the underlying operating system, which may not permit file names long enough to include 255-character host names. This affects thegeneral_log_file,log_error,pid_file,relay_log, andslow_query_log_file system variables and corresponding options. If host name-based values are too long for the OS, explicit shorter values must be provided.
- Although the server now supports 255-character host names, connections to the server established using the--ssl-mode=VERIFY_IDENTITY option are constrained by maximum host name length supported by OpenSSL. Host name matches pertain to two fields of SSL certificates, which have maximum lengths as follows: Common Name: maximum length 64; Subject Alternative Name: maximum length as per RFC#1034.
- The increase in permitted host name length can affect tables with indexes on host name columns. For example, tables in the
- Plugins. Previously, MySQL plugins could be written in C or C++. MySQL header files used by plugins now contain C++ code, which means that plugins must be written in C++, not C.
- C API. The MySQL C API now supports asynchronous functions for nonblocking communication with the MySQL server. Each function is the asynchronous counterpart to an existing synchronous function. The synchronous functions block if reads from or writes to the server connection must wait. The asynchronous functions enable an application to check whether work on the server connection is ready to proceed. If not, the application can perform other work before checking again later. SeeC API Asynchronous Interface.
- Additional target types for casts. The functions CAST() andCONVERT() now support conversions to typesDOUBLE,FLOAT, andREAL. Added in MySQL 8.0.17. See Section 14.10, “Cast Functions and Operators”.
- JSON schema validation. MySQL 8.0.17 adds two functionsJSON_SCHEMA_VALID() andJSON_SCHEMA_VALIDATION_REPORT() for validating JSON documents again JSON schemas.
JSON_SCHEMA_VALID()
returns TRUE (1) if the document validates against the schema and FALSE (0) if it does not.JSON_SCHEMA_VALIDATION_REPORT()
returns a JSON document containing detailed information about the results of the validation. The following statements apply to both of these functions:- The schema must conform to Draft 4 of the JSON Schema specification.
required
attributes are supported.- External resources and the
$ref
keyword are not supported. - Regular expression patterns are supported; invalid patterns are silently ignored.
See Section 14.17.7, “JSON Schema Validation Functions”, for more information and examples.
- Multi-valued indexes. Beginning with MySQL 8.0.17,InnoDB supports the creation of a multi-valued index, which is a secondary index defined on a JSON column that stores an array of values and which can have multiple index records for a single data record. Such an index uses a key part definition such as
CAST(data->'$.zipcode' AS UNSIGNED ARRAY)
. A multi-valued index is used automatically by the MySQL optimizer for suitable queries, as can be viewed in the output ofEXPLAIN.
As part of this work, MySQL adds a new functionJSON_OVERLAPS() and a newMEMBER OF() operator for working with JSON documents, additionally extending theCAST() function with a newARRAY
keyword, as described in the following list:JSON_OVERLAPS()
compares twoJSON documents. If they contain any key-value pairs or array elements in common, the function returns TRUE (1); otherwise it returns FALSE (0). If both values are scalars, the function performs a simple test for equality. If one argument is a JSON array and the other is a scalar, the scalar is treated as an array element. Thus,JSON_OVERLAPS()
acts as a complement to JSON_CONTAINS().MEMBER OF()
tests whether the first operand (a scalar or JSON document) is a member of the JSON array passed as the second operand, returning TRUE (1) if it is, and FALSE (0) if it is not. No type conversion of the operand is performed.CAST(`expression` AS`type` ARRAY)
permits creation of a functional index by casting the JSON array found in a JSON document at_jsonpath
_ to an SQL array. Type specifiers are limited to those already supported byCAST()
, with the exception ofBINARY
(not supported). This usage ofCAST()
(and theARRAY
keyword) is supported only byInnoDB, and only for the creation of a multi-valued index.
For detailed information about multi-valued indexes, including examples, seeMulti-Valued Indexes.Section 14.17.3, “Functions That Search JSON Values”, provides information aboutJSON_OVERLAPS()
andMEMBER OF()
, along with examples of use.
- Hintable time_zone. As of MySQL 8.0.17, thetime_zone session variable is hintable usingSET_VAR.
- Redo Log Archiving. As of MySQL 8.0.17,
InnoDB
supports redo log archiving. Backup utilities that copy redo log records may sometimes fail to keep pace with redo log generation while a backup operation is in progress, resulting in lost redo log records due to those records being overwritten. The redo log archiving feature addresses this issue by sequentially writing redo log records to an archive file. Backup utilities can copy redo log records from the archive file as necessary, thereby avoiding the potential loss of data. For more information, see Redo Log Archiving. - The Clone Plugin. As of MySQL 8.0.17, MySQL provides a clone plugin that permits cloning
InnoDB
data locally or from a remote MySQL server instance. A local cloning operation stores cloned data on the same server or node where the MySQL instance runs. A remote cloning operation transfers cloned data over the network from a donor MySQL server instance to the recipient server or node where the cloning operation was initiated.
The clone plugin supports replication. In addition to cloning data, a cloning operation extracts and transfers replication coordinates from the donor and applies them on the recipient, which enables using the clone plugin for provisioning Group Replication members and replicas. Using the clone plugin for provisioning is considerably faster and more efficient than replicating a large number of transactions. Group Replication members can also be configured to use the clone plugin as an alternative method of recovery, so that members automatically choose the most efficient way to retrieve group data from seed members.
For more information, see Section 7.6.7, “The Clone Plugin”, and Section 20.5.4.2, “Cloning for Distributed Recovery”.
As of MySQL 8.0.27, concurrent DDL operations on the donor MySQL Server instance are permitted while a cloning operation is in progress. Previously, a backup lock was held during the cloning operation, preventing concurrent DDL on the donor. To revert to the previous behavior of blocking concurrent DDL on the donor during a clone operation, enable the clone_block_ddl variable. See Section 7.6.7.4, “Cloning and Concurrent DDL”.
As of MySQL 8.0.29, theclone_delay_after_data_drop variable permits specifying a delay period immediately after removing existing data on the recipient MySQL Server instance at the start of a remote cloning operation. The delay is intended to provide enough time for the file system on the recipient host to free space before data is cloned from the donor MySQL Server instance. Certain file systems free space asynchronously in a background process. On these file systems, cloning data too soon after dropping existing data can result in clone operation failures due to insufficient space. The maximum delay period is 3600 seconds (1 hour). The default setting is 0 (no delay).
As of MySQL 8.0.37, cloning is allowed between different point releases. In other words, only the major and minor version numbers must match when previously the point release number also had to match.
For example, clone functionality now permits cloning 8.0.37 to 8.0.41 or 8.0.51 to 8.0.39. Previous restrictions still apply to versions older than 8.0.37, so cloning the likes of 8.0.36 to 8.0.42 or vice-versa is not permitted. - Hash Join Optimization. Beginning with MySQL 8.0.18, a hash join is used whenever each pair of tables in a join includes at least one equi-join condition, and no indexes apply to any join condition. A hash join does not require indexes, although it can be used with indexes applying to single-table predicates only. A hash join is more efficient in most cases than the block-nested loop algorithm. Joins such as those shown here can be optimized in this manner:
SELECT *
FROM t1
JOIN t2
ON t1.c1=t2.c1;
SELECT *
FROM t1
JOIN t2
ON (t1.c1 = t2.c1 AND t1.c2 < t2.c2)
JOIN t3
ON (t2.c1 = t3.c1)
Hash joins can also be used for Cartesian products—that is, when no join condition is specified.
You can see when the hash join optimization is being used for a particular query usingEXPLAIN FORMAT=TREE or EXPLAIN ANALYZE. (In MySQL 8.0.20 and later, you can also use EXPLAIN
, omittingFORMAT=TREE
.)
The amount of memory available to a hash join is limited by the value ofjoin_buffer_size. A hash join that requires more than this much memory is executed on disk; the number of disk files that can be used by an on-disk hash join is limited byopen_files_limit.
As of MySQL 8.0.19, thehash_join optimizer switch which was introduced in MySQL 8.0.18 no longer supported (hash_join=on still appears as part of the value of optimizer_switch, but setting it no longer has any effect). The HASH_JOIN andNO_HASH_JOIN
optimizer hints are also no longer supported. The switch and the hint are both now deprecated; expect them to be removed in a future MySQL release. In MySQL 8.0.18 and later, hash joins can be disabled using the NO_BNL optimizer switch.
In MySQL 8.0.20 and later, block nested loop is no longer used in the MySQL server, and a hash join is employed any time a block nested loop would have been used previously, even when the query contains no equi-join conditions. This applies to inner non-equijoins, semijoins, antijoins, left outer joins, and right outer joins. Theblock_nested_loop flag for the optimizer_switch system variable as well as theBNL andNO_BNL
optimizer hints are still supported, but henceforth control use of hash joins only. In addition, both inner and outer joins (including semijoins and antijoins) can now employ batched key access (BKA), which allocates join buffer memory incrementally so that individual queries need not use up large amounts of resources that they do not actually require for resolution. BKA for inner joins only is supported starting with MySQL 8.0.18.
MySQL 8.0.20 also replaces the executor used in previous versions of MySQL with the iterator executor. This work includes replacement of the old index subquery engines that governed queries of the form WHERE_`value`_ IN (SELECT_`column`_ FROM_`table`_ WHERE ...)
for those IN
queries which have not been optimized as semijoins, as well as queries materialized in the same form, which formerly depended on the old executor.
For more information and examples, seeSection 10.2.1.4, “Hash Join Optimization”. See alsoBatched Key Access Joins.
- EXPLAIN ANALYZE Statement. A new form of the EXPLAIN statement, EXPLAIN ANALYZE, is implemented in MySQL 8.0.18, providing expanded information about the execution ofSELECT statements in
TREE
format for each iterator used in processing the query, and making it possible to compare estimated cost with the actual cost of the query. This information includes startup cost, total cost, number of rows returned by this iterator, and the number of loops executed.
In MySQL 8.0.21 and later, this statement also supports aFORMAT=TREE
specifier.TREE
is the only supported format.
See Obtaining Information with EXPLAIN ANALYZE, for more information. - Query cast injection. In version 8.0.18 and later, MySQL injects cast operations into the query item tree inside expressions and conditions in which the data type of the argument and the expected data type do not match. This has no effect on query results or speed of execution, but makes the query as executed equivalent to one which is compliant with the SQL standard while maintaining backwards compatibility with previous releases of MySQL.
Such implicit casts are now performed between temporal types (DATE,DATETIME,TIMESTAMP,TIME) and numeric types (SMALLINT,TINYINT,MEDIUMINT,INT/INTEGER,BIGINT;DECIMAL/NUMERIC;FLOAT,DOUBLE,REAL;BIT) whenever they are compared using any of the standard numeric comparison operators (=,>=,>,<,<=,<>/!=, or<=>). In this case, any value that is not already aDOUBLE
is cast as one. Cast injection is also now performed for comparisons betweenDATE orTIME values andDATETIME values, where the arguments are cast whenever necessary asDATETIME
.
Beginning with MySQL 8.0.21, such casts are also performed when comparing string types with other types. String types that are cast include CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM, andSET. When comparing a value of a string type with a numeric type orYEAR
, the string cast is toDOUBLE
; if the type of the other argument is notFLOAT
,DOUBLE
, orREAL
, it is also cast toDOUBLE
. When comparing a string type to aDATETIME
orTIMESTAMP
value, the string is cast is toDATETIME
; when comparing a string type withDATE
, the string is cast toDATE
.
It is possible to see when casts are injected into a given query by viewing the output of EXPLAIN ANALYZE,EXPLAIN FORMAT=JSON
, or, as shown here,EXPLAIN FORMAT=TREE
:
mysql> CREATE TABLE d (dt DATETIME, d DATE, t TIME);
Query OK, 0 rows affected (0.62 sec)
mysql> CREATE TABLE n (i INT, d DECIMAL, f FLOAT, dc DECIMAL);
Query OK, 0 rows affected (0.51 sec)
mysql> CREATE TABLE s (c CHAR(25), vc VARCHAR(25),
-> bn BINARY(50), vb VARBINARY(50), b BLOB, t TEXT,
-> e ENUM('a', 'b', 'c'), se SET('x' ,'y', 'z'));
Query OK, 0 rows affected (0.50 sec)
mysql> EXPLAIN FORMAT=TREE SELECT * from d JOIN n ON d.dt = n.i\G
*************************** 1. row ***************************
EXPLAIN: -> Inner hash join (cast(d.dt as double) = cast(n.i as double))
(cost=0.70 rows=1)
-> Table scan on n (cost=0.35 rows=1)
-> Hash
-> Table scan on d (cost=0.35 rows=1)
mysql> EXPLAIN FORMAT=TREE SELECT * from s JOIN d ON d.dt = s.c\G
*************************** 1. row ***************************
EXPLAIN: -> Inner hash join (d.dt = cast(s.c as datetime(6))) (cost=0.72 rows=1)
-> Table scan on d (cost=0.37 rows=1)
-> Hash
-> Table scan on s (cost=0.35 rows=1)
1 row in set (0.01 sec)
mysql> EXPLAIN FORMAT=TREE SELECT * from n JOIN s ON n.d = s.c\G
*************************** 1. row ***************************
EXPLAIN: -> Inner hash join (cast(n.d as double) = cast(s.c as double)) (cost=0.70 rows=1)
-> Table scan on s (cost=0.35 rows=1)
-> Hash
-> Table scan on n (cost=0.35 rows=1)
1 row in set (0.00 sec)
Such casts can also be seen by executing EXPLAIN [FORMAT=TRADITIONAL]
, in which case it is also necessary to issue SHOW WARNINGS after executing theEXPLAIN
statement.
- Time zone support for TIMESTAMP and DATETIME. As of MySQL 8.0.19, the server accepts a time zone offset with inserted datetime (TIMESTAMP andDATETIME) values. This offset uses the same format as that employed when setting the time_zone system variable, except that a leading zero is required when the hours portion of the offset is less than 10, and
'-00:00'
is not allowed. Examples of datetime literals that include time zone offsets are'2019-12-11 10:40:30-05:00'
,'2003-04-14 03:30:00+10:00'
, and'2020-01-01 15:35:45+05:30'
.
Time zone offsets are not displayed when selecting datetime values.
Datetime literals incorporating time zone offsets can be used as prepared statement parameter values.
As part of this work, the value used to set thetime_zone system variable is now also restricted to the range-13:59
to+14:00
, inclusive. (It remains possible to assign name values totime_zone
such as'EST'
,'Posix/Australia/Brisbane'
, and'Europe/Stockholm'
to this variable, provided that the MySQL time zone tables are loaded; seePopulating the Time Zone Tables).
For more information and examples, seeSection 7.1.15, “MySQL Server Time Zone Support”, as well asSection 13.2.2, “The DATE, DATETIME, and TIMESTAMP Types”. - Precise information for JSON schema CHECK constraint failures. When usingJSON_SCHEMA_VALID() to specify a
CHECK
constraint, MySQL 8.0.19 and later provides precise information about the reasons for failures of such constraints.
For examples and more information, seeJSON_SCHEMA_VALID() and CHECK constraints. See also Section 15.1.20.6, “CHECK Constraints”. - Row and column aliases with ON DUPLICATE KEY UPDATE. Beginning with MySQL 8.0.19, it is possible to reference the row to be inserted, and, optionally, its columns, using aliases. Consider the followingINSERT statement on a table
t
having columnsa
andb
:
INSERT INTO t SET a=9,b=5
ON DUPLICATE KEY UPDATE a=VALUES(a)+VALUES(b);
Using the alias new
for the new row, and, in some cases, the aliases m
andn
for this row's columns, theINSERT
statement can be rewritten in many different ways, some examples of which are shown here:
INSERT INTO t SET a=9,b=5 AS new
ON DUPLICATE KEY UPDATE a=new.a+new.b;
INSERT INTO t VALUES(9,5) AS new
ON DUPLICATE KEY UPDATE a=new.a+new.b;
INSERT INTO t SET a=9,b=5 AS new(m,n)
ON DUPLICATE KEY UPDATE a=m+n;
INSERT INTO t VALUES(9,5) AS new(m,n)
ON DUPLICATE KEY UPDATE a=m+n;
For more information and examples, seeSection 15.2.7.2, “INSERT ... ON DUPLICATE KEY UPDATE Statement”.
- SQL standard explicit table clause and table value constructor. Added table value constructors and explicit table clauses according to the SQL standard. These are implemented in MySQL 8.0.19, respectively, as theTABLE statement and theVALUES statement.
The TABLE statement has the formatTABLE_`tablename`_
, and is equivalent toSELECT * FROM_`tablename`_
. It supportsORDER BY
andLIMIT
clauses ( the latter with optionalOFFSET
), but does not allow for the selection of individual table columns.TABLE
can be used anywhere that you would employ the equivalent SELECT statement; this includes joins, unions,INSERT ... SELECT, REPLACE,CREATE TABLE ... SELECT statements, and subqueries. For example:TABLE t1 UNION TABLE t2
is equivalent toSELECT * FROM t1 UNION SELECT * FROM t2
CREATE TABLE t2 TABLE t1
is equivalent toCREATE TABLE t2 SELECT * FROM t1
SELECT a FROM t1 WHERE b > ANY (TABLE t2)
is equivalent toSELECT a FROM t1 WHERE b > ANY (SELECT * FROM t2)
.
VALUES can be used to supply a table value to an INSERT,REPLACE, orSELECT statement, and consists of theVALUES
keyword followed by a series of row constructors (ROW()
) separated by commas. For example, the statementINSERT INTO t1 VALUES ROW(1,2,3), ROW(4,5,6), ROW(7,8,9)
provides an SQL-compliant equivalent to the MySQL-specificINSERT INTO t1 VALUES (1,2,3), (4,5,6), (7,8,9)
. You can also select from aVALUES table value constructor just as you would a table, bearing in mind that you must supply a table alias when doing so, and use thisSELECT just as you would any other; this includes joins, unions, and subqueries.
For more information aboutTABLE
andVALUES
, and for examples of their use, see the following sections of this documentation:- Section 15.2.16, “TABLE Statement”
- Section 15.2.19, “VALUES Statement”
- Section 15.1.20.4, “CREATE TABLE ... SELECT Statement”
- Section 15.2.7.1, “INSERT ... SELECT Statement”
- Section 15.2.13.2, “JOIN Clause”
- Section 15.2.15, “Subqueries”
- Section 15.2.18, “UNION Clause”
- Optimizer hints for FORCE INDEX, IGNORE INDEX. MySQL 8.0 introduces index-level optimizer hints which serve as analogs to the traditional index hints as described in Section 10.9.4, “Index Hints”. The new hints are listed here, along with their
FORCE INDEX
orIGNORE INDEX
equivalents:- GROUP_INDEX: Equivalent to
FORCE INDEX FOR GROUP BY
NO_GROUP_INDEX: Equivalent toIGNORE INDEX FOR GROUP BY
- JOIN_INDEX: Equivalent to
FORCE INDEX FOR JOIN
NO_JOIN_INDEX: Equivalent toIGNORE INDEX FOR JOIN
- ORDER_INDEX: Equivalent to
FORCE INDEX FOR ORDER BY
NO_ORDER_INDEX: Equivalent toIGNORE INDEX FOR ORDER BY
- INDEX: Same asGROUP_INDEX plusJOIN_INDEX plusORDER_INDEX; equivalent to
FORCE INDEX
with no modifier
NO_INDEX: Same asNO_GROUP_INDEX plusNO_JOIN_INDEX plusNO_ORDER_INDEX; equivalent toIGNORE INDEX
with no modifier
For example, the following two queries are equivalent:
- GROUP_INDEX: Equivalent to
SELECT a FROM t1 FORCE INDEX (i_a) FOR JOIN WHERE a=1 AND b=2;
SELECT /*+ JOIN_INDEX(t1 i_a) */ a FROM t1 WHERE a=1 AND b=2;
The optimizer hints listed previously follow the same basic rules for syntax and usage as existing index-level optimizer hints.
These optimizer hints are intended to replace FORCE INDEX
and IGNORE INDEX
, which we plan to deprecate in a future MySQL release, and subsequently to remove from MySQL. They do not implement a single exact equivalent for USE INDEX
; instead, you can employ one or more ofNO_INDEX,NO_JOIN_INDEX,NO_GROUP_INDEX, orNO_ORDER_INDEX to achieve the same effect.
For further information and examples of use, seeIndex-Level Optimizer Hints.
- JSON_VALUE() function. MySQL 8.0.21 implements a new functionJSON_VALUE() intended to simplify indexing of JSON columns. In its most basic form, it takes as arguments a JSON document and a JSON path pointing to a single value in that document, as well as (optionally) allowing you to specify a return type with the
RETURNING
keyword.JSON_VALUE(_`jsondoc`_,_`path`_ RETURNING_`type`_)
is equivalent to this:
CAST(
JSON_UNQUOTE( JSON_EXTRACT(json_doc, path) )
AS type
);
You can also specify ON EMPTY
,ON ERROR
, or both clauses, similar to those employed withJSON_TABLE().
You can use JSON_VALUE()
to create an index on an expression on a JSON
column like this:
CREATE TABLE t1(
j JSON,
INDEX i1 ( (JSON_VALUE(j, '$.id' RETURNING UNSIGNED)) )
);
INSERT INTO t1 VALUES ROW('{"id": "123", "name": "shoes", "price": "49.95"}');
A query using this expression, such as that shown here, can make use of the index:
SELECT j->"$.name" as name, j->"$.price" as price
FROM t1
WHERE JSON_VALUE(j, '$.id' RETURNING UNSIGNED) = 123;
In many cases, this is simpler than creating a generated column from the JSON
column and then creating an index on the generated column.
For more information and examples, see the description ofJSON_VALUE().
- User comments and user attributes. MySQL 8.0.21 introduces the ability to set user comments and user attributes when creating or updating user accounts. A user comment consists of arbitrary text passed as the argument to a
COMMENT
clause used with a CREATE USER orALTER USER statement. A user attribute consists of data in the form of a JSON object passed as the argument to anATTRIBUTE
clause used with either of these two statements. The attribute can contain any valid key-value pairs in JSON object notation. Only one ofCOMMENT
orATTRIBUTE
can be used in a singleCREATE USER
orALTER USER
statement.
User comments and user attributes are stored together internally as a JSON object, the comment text as the value of an element havingcomment
as its key. This information can be retrieved from theATTRIBUTE
column of the Information Schema USER_ATTRIBUTES table; since it is in JSON format, you can use MySQL's JSON function and operators to parse its contents (seeSection 14.17, “JSON Functions”). Successive changes to the user attribute are merged with its current value as when using the JSON_MERGE_PATCH() function.
Example:
mysql> CREATE USER 'mary'@'localhost' COMMENT 'This is Mary Smith\'s account';
Query OK, 0 rows affected (0.33 sec)
mysql> ALTER USER 'mary'@'localhost'
-≫ ATTRIBUTE '{"fname":"Mary", "lname":"Smith"}';
Query OK, 0 rows affected (0.14 sec)
mysql> ALTER USER 'mary'@'localhost'
-≫ ATTRIBUTE '{"email":"mary.smith@example.com"}';
Query OK, 0 rows affected (0.12 sec)
mysql> SELECT
-> USER,
-> HOST,
-> ATTRIBUTE->>"$.fname" AS 'First Name',
-> ATTRIBUTE->>"$.lname" AS 'Last Name',
-> ATTRIBUTE->>"$.email" AS 'Email',
-> ATTRIBUTE->>"$.comment" AS 'Comment'
-> FROM INFORMATION_SCHEMA.USER_ATTRIBUTES
-> WHERE USER='mary' AND HOST='localhost'\G
*************************** 1. row ***************************
USER: mary
HOST: localhost
First Name: Mary
Last Name: Smith
Email: mary.smith@example.com
Comment: This is Mary Smith's account
1 row in set (0.00 sec)
For more information and examples, seeSection 15.7.1.3, “CREATE USER Statement”, Section 15.7.1.1, “ALTER USER Statement”, andSection 28.3.46, “The INFORMATION_SCHEMA USER_ATTRIBUTES Table”.
- New optimizer_switch flags. MySQL 8.0.21 adds two new flags for theoptimizer_switch system variable, as described in the following list:
- prefer_ordering_index flag
By default, MySQL attempts to use an ordered index for anyORDER BY
orGROUP BY
query that has aLIMIT
clause, whenever the optimizer determines that this would result in faster execution. Because it is possible in some cases that choosing a different optimization for such queries actually performs better, it is now possible to disable this optimization by setting theprefer_ordering_index flag tooff
.
The default value for this flag ison
. - subquery_to_derived flag
When this flag is set toon
, the optimizer transforms eligible scalar subqueries into joins on derived tables. For example, the querySELECT * FROM t1 WHERE t1.a > (SELECT COUNT(a) FROM t2)
is rewritten asSELECT t1.a FROM t1 JOIN ( SELECT COUNT(t2.a) AS c FROM t2 ) AS d WHERE t1.a > d.c
.
This optimization can be applied to a subquery which is part of aSELECT
,WHERE
,JOIN
, orHAVING
clause; contains one or more aggregate functions but noGROUP BY
clause; is not correlated; and does not use any nondeterministic functions.
The optimization can also be applied to a table subquery which is the argument toIN
,NOT IN
,EXISTS
, orNOT EXISTS
, and which does not contain aGROUP BY
. For example, the querySELECT * FROM t1 WHERE t1.b < 0 OR t1.a IN (SELECT t2.a + 1 FROM t2)
is rewritten asSELECT a, b FROM t1 LEFT JOIN (SELECT DISTINCT 1 AS e1, t2.a AS e2 FROM t2) d ON t1.a + 1 = d.e2 WHERE t1.b < 0 OR d.e1 IS NOT NULL
.
Starting with MySQL 8.0.24, this optimization can also be applied to a correlated scalar subquery by applying an extra grouping to it, and then an outer join on the lifted predicate. For example, a query such asSELECT * FROM t1 WHERE (SELECT a FROM t2 WHERE t2.a=t1.a) > 0
can be rewritten asSELECT t1.* FROM t1 LEFT OUTER JOIN (SELECT a, COUNT(*) AS ct FROM t2 GROUP BY a) AS derived ON t1.a = derived.a WHERE derived.a > 0
. MySQL performs a cardinality check to make sure that the subquery does not return more than one row (ER_SUBQUERY_NO_1_ROW). See Section 15.2.15.7, “Correlated Subqueries”, for more information.
This optimization is normally disabled, since it does not yield a noticeable performance benefit in most cases; the flag is set tooff
by default.
For more information, seeSection 10.9.2, “Switchable Optimizations”. See alsoSection 10.2.1.19, “LIMIT Query Optimization”,Section 10.2.2.1, “Optimizing IN and EXISTS Subquery Predicates with Semijoin Transformations”, andSection 10.2.2.4, “Optimizing Derived Tables, View References, and Common Table Expressions with Merging or Materialization”.
- prefer_ordering_index flag
- XML enhancements. As of MySQL 8.0.21, the LOAD XML statement now supports
CDATA
sections in the XML to be imported. - Casting to the YEAR type now supported. Beginning with MySQL 8.0.22, the server allows casting toYEAR. Both theCAST() andCONVERT() functions support single-digit, two-digit, and four-digit
YEAR
values. For one-digit and two-digit values, the allowed range is 0-99. Four-digit values must be in the range 1901-2155.YEAR
can also be used as the return type for the JSON_VALUE() function; this function supports four-digit years only.
String, time-and-date, and floating-point values can all be cast toYEAR
. Casting ofGEOMETRY values toYEAR
is not supported.
For more information, including conversion rules, see the description of the CONVERT() function. - Retrieval of TIMESTAMP values as UTC. MySQL 8.0.22 and later supports conversion of aTIMESTAMP column value from the system time zone to a UTCDATETIME on retrieval, using
CAST(_`value`_ AT TIME ZONE _`specifier`_ AS DATETIME)
, where the specifier is one of[INTERVAL] '+00:00'
or'UTC'
. The precision of theDATETIME
value returned by the cast can be specified up to 6 decimal places, if desired. TheARRAY
keyword is not supported with this construct.TIMESTAMP
values inserted into a table using a timezone offset are also supported. Use ofAT TIME ZONE
is not supported forCONVERT() or any other MySQL function or construct.
For further information and examples, see the description of the CAST() function. - Dump file output synchronization. MySQL 8.0.22 and later supports periodic synchronization when writing to files bySELECT INTO DUMPFILE and
SELECT INTO OUTFILE
statements. This can be enabled by setting theselect_into_disk_sync system variable toON
; the size of the write buffer is determined by the value set forselect_into_buffer_size; the default is 131072 (217) bytes.
In addition, an optional delay following synchronization to disk can be set usingselect_into_disk_sync_delay; the default is no delay (0 milliseconds).
For more information, see the descriptions of the variables referenced previously in this item. - Single preparation of statements. As of MySQL 8.0.22, a prepared statement is prepared a single time, rather than once each time it is executed. This is done when executingPREPARE. This is also true for any statement inside a stored procedure; the statement is prepared once, when the stored procedure is first executed.
One result of this change is that the fashion in which dynamic parameters used in prepared statements are resolved is also changed in the ways listed here:- A prepared statement parameter is assigned a data type when the statement is prepared; the type persists for each subsequent execution of the statement (unless the statement is reprepared; see following).
Using a different data type for a given parameter or user variable within a prepared statement for executions of the statement subsequent to the first execution may cause the statement to be reprepared; for this reason, it is advisable to use the same data type for a given parameter when re-executing a prepared statement. - The following constructs employing window functions are no longer accepted, in order to align with the SQL standard:
* NTILE(NULL)
* NTH_VALUE(expr, NULL)
* LEAD(expr,nn) andLAG(expr,nn), where_nn
_ is a negative number
This facilitates greater compliance with the SQL standard. See the individual function descriptions for further details.
- A user variable referenced within a prepared statement now has its data type determined when the statement is prepared; the type persists for each subsequent execution of the statement.
- A user variable referenced by a statement occurring within a stored procedure now has its data type determined the first time the statement is executed; the type persists for any subsequent invocation of the containing stored procedure.
- When executing a prepared statement of the form
SELECT _`expr1`_,_`expr2`_, ... FROM_`table`_ ORDER BY ?
, passing an integer valueN
for the parameter no longer causes ordering of the results by the_N
th expression in the select list; the results are no longer ordered, as is expected with `` ORDER BYconstant
_ ``.
Preparing a statement used as a prepared statement or within a stored procedure only once enhances the performance of the statement, since it negates the added cost of repeated preparation. Doing so also avoids possible multiple rollbacks of preparation structures, which has been the source of numerous issues in MySQL.
For more information, see Section 15.5.1, “PREPARE Statement”.
- A prepared statement parameter is assigned a data type when the statement is prepared; the type persists for each subsequent execution of the statement (unless the statement is reprepared; see following).
- RIGHT JOIN as LEFT JOIN handling. As of MySQL 8.0.22, the server handles all instances of
RIGHT JOIN
internally asLEFT JOIN
, eliminating a number of special cases in which a complete conversion was not performed at parse time. - Derived condition pushdown optimization. MySQL 8.0.22 (and later) implements derived condition pushdown for queries having materialized derived tables. For a query such as
SELECT * FROM (SELECT i, j FROM t1) AS dt WHERE i >_`constant`_
, it is now possible in many cases to push the outerWHERE
condition down to the derived table, in this case resulting inSELECT * FROM (SELECT i, j FROM t1 WHERE i >_`constant`_) AS dt
.
Previously, if the derived table was materialized and not merged, MySQL materialized the entire table, then qualified the rows with theWHERE
condition. Moving theWHERE
condition into the subquery using the derived condition pushdown optimization can often reduce the number of rows must be processed, which can decrease the time needed to execute the query.
An outerWHERE
condition can be pushed down directly to a materialized derived table when the derived table does not use any aggregate or window functions. When the derived table has aGROUP BY
and does not use any window functions, the outerWHERE
condition can be pushed down to the derived table as aHAVING
condition. TheWHERE
condition can also be pushed down when the derived table uses a window function and the outerWHERE
references columns used in the window function'sPARTITION
clause.
Derived condition pushdown is enabled by default, as indicated by theoptimizer_switch system variable'sderived_condition_pushdown flag. The flag, added in MySQL 8.0.22, is set toon
by default; to disable the optimization for a specific query, you can use theNO_DERIVED_CONDITION_PUSHDOWN optimizer hint (also added in MySQL 8.0.22). If the optimization is disabled due toderived_condition_pushdown being set tooff
, you can enable it for a given query usingDERIVED_CONDITION_PUSHDOWN.
The derived condition pushdown optimization cannot be employed for a derived table that contains aLIMIT
clause. Prior to MySQL 8.0.29, the optimization also cannot be used when the query containsUNION. In MySQL 8.0.29 and later, conditions can be pushed down to both query blocks of a union in most cases; seeSection 10.2.2.5, “Derived Condition Pushdown Optimization”, for more information.
In addition, a condition that itself uses a subquery cannot be pushed down, and aWHERE
condition cannot be pushed down to a derived table that is also an inner table of an outer join. For additional information and examples, seeSection 10.2.2.5, “Derived Condition Pushdown Optimization”. - Non-locking reads on MySQL grant tables. As of MySQL 8.0.22, to permit concurrent DML and DDL operations on MySQL grant tables, read operations that previously acquired row locks on MySQL grant tables are executed as non-locking reads.
The operations that are now performed as non-locking reads on MySQL grant tables include:- SELECT statements and other read-only statements that read data from grant tables through join lists and subqueries, includingSELECT ... FOR SHARE statements, using any transaction isolation level.
- DML operations that read data from grant tables (through join lists or subqueries) but do not modify them, using any transaction isolation level.
For additional information, seeGrant Table Concurrency.
- 64-bit support for FROM_UNIXTIME(), UNIX_TIMESTAMP(), CONVERT_TZ(). As of MySQL 8.0.28, the functionsFROM_UNIXTIME(),UNIX_TIMESTAMP(), andCONVERT_TZ() handle 64-bit values on platforms that support them. This includes 64-bit versions of Linux, MacOS, and Windows.
On compatible platforms,UNIX_TIMESTAMP()
now handles values up to'3001-01-18 23:59:59.999999'
UTC, andFROM_UNIXTIME()
can convert values up to 32536771199.999999 seconds since the Unix Epoch;CONVERT_TZ()
now accepts values that do not exceed'3001-01-18 23:59:59.999999'
UTC following conversion.
The behavior of these functions on 32-bit platforms is unaffected by these changes. The behavior of theTIMESTAMP type is also not affected (on any platform); for working with datetimes after'2038-01-19 03:14:07.999999'
, UTC, use the DATETIME type instead.
For more information, see the descriptions of the individual functions just discussed, inSection 14.7, “Date and Time Functions”. - Resource allocation control. Beginning with MySQL 8.0.28, you can see the amount of memory used for queries issued by all regular users by checking theGlobal_connection_memory status variable. (This total does not include resources used by system users such as MySQL root. It is also exclusive of any memory taken by theInnoDB buffer pool.)
To enable updates ofGlobal_connection_memory
, it is necessary to setglobal_connection_memory_tracking = 1; this is0
(off) by default. You can control how oftenGlobal_connection_memory
is updated by settingconnection_memory_chunk_size.
It is also possible to set memory usage limits for normal users on the session or global level, or both, by setting either or both of the system variables listed here:- connection_memory_limit: Amount of memory allocated for each connection. Whenever this limit is exceeded for any user, new queries from this user are rejected.
- global_connection_memory_limit: Amount of memory allocated for all connections. Whenever this limit is exceeded, new queries from any regular user are rejected.
These limits do not apply to system processes or administrative accounts.
See the descriptions of the referenced variables for more information.
- Detached XA transactions. MySQL 8.0.29 adds support for XA transactions which, once prepared, are no longer connected to the originating connection. This means that they can be committed or rolled back by another connection, and that the current session can immediately begin another transaction.
A system variablexa_detach_on_prepare controls whether XA transaction are detached; the default isON
, which causes all XA transactions to be detached. Use of temporary tables is disallowed for XA transactions when this is in effect.
For more information, see Section 15.3.8.2, “XA Transaction States”. - Automatic binary log purge control. MySQL 8.0.29 adds thebinlog_expire_logs_auto_purge system variable, which provides a single interface for enabling and disabling automatic purging of the binary logs. This is enabled (
ON
) by default; to disable automatic purging of the binary log files, set this variable toOFF
.binlog_expire_logs_auto_purge
must beON
in order for automatic purging of the binary log files to proceed; the value of this variable takes precedence over that of any other server option or variable, including (but not exclusive to)binlog_expire_logs_seconds.
The setting forbinlog_expire_logs_auto_purge
has no effect on PURGE BINARY LOGS. - Conditional routine and trigger creation statements. Beginning with MySQL 8.0.29, the following statements support an
IF NOT EXISTS
option:- CREATE FUNCTION
- CREATE PROCEDURE
- CREATE TRIGGER
ForCREATE FUNCTION
when creating a stored function andCREATE PROCEDURE
, this option prevents an error from occurring if there is already a routine having the same name. ForCREATE FUNCTION when used to create a loadable function, the option prevents an error if there already exists a loadable function having that name. ForCREATE TRIGGER
, the option prevents an error from occurring if there already exists in the same schema and on the same table a trigger having the same name.
This enhancement aligns the syntax of these statements more closely with that of CREATE DATABASE, CREATE TABLE, CREATE USER, and CREATE EVENT (all of which already supportIF NOT EXISTS
), and acts to complement theIF EXISTS
option supported by DROP PROCEDURE,DROP FUNCTION, andDROP TRIGGER statements.
For more information, see the descriptions of the indicated SQL statements, as well asFunction Name Resolution. See alsoSection 19.5.1.7, “Replication of CREATE TABLE ... SELECT Statements”.
- Included FIDO library upgrade. MySQL 8.0.30 upgrades the included
fido2
library (used with theauthentication_fido
plugin) from version 1.5.0 to version 1.8.0.
See Section 8.4.1.11, “FIDO Pluggable Authentication”, for more information. - Character sets: Language-specific collations. Previously, when more than one language had the exact same collation definition, MySQL implemented collations for only one of the languages, which meant that some languages were covered only by
utf8mb4
Unicode 9.0 collations specific to other languages. MySQL 8.0.30 (and later) fixes such issues by providing language-specific collations for those languages that were previously covered only by language-specific collations for other languages. Languages covered by the new collations are listed here:- Norwegian (Nynorsk)
and
Norwegian (Bokmål) - Serbian (Latin characters)
- Bosnian (Latin characters)
- Bulgarian
- Galician
- Mongolian (Cyrillic characters)
MySQL provides*_as_cs
and*_ai_ci
collations for each of the languages just listed.
For more information, seeLanguage-Specific Collations.
- Norwegian (Nynorsk)
- IF EXISTS and IGNORE UNKNOWN USER options for REVOKE. MySQL 8.0.30 implements two new options forREVOKE which can be used to determine whether a statement yields an error or a warning when a user, role, or privilege specified in the statement cannot be found, or cannot be assigned. Very basic syntax showing the placement of these new options is provided here:
REVOKE [IF EXISTS] privilege_or_role
ON object
FROM user_or_role [IGNORE UNKNOWN USER]
IF EXISTS
causes an unsuccessfulREVOKE
statement to raise a warning instead of an error, as long as the named target user or role actually exists, despite any references in the statement to any roles or privileges which cannot be found.IGNORE UNKNOWN USER
causes an unsuccessful REVOKE
to raise a warning rather than an error when the target user or role named in the statement cannot be found.
For further information and examples, seeSection 15.7.1.8, “REVOKE Statement”.
- Generated invisible primary keys. Beginning with MySQL 8.0.30, it is possible to run a replication source server such that a generated invisible primary key (GIPK) is added to anyInnoDB table that is created without an explicit primary key. The generated key column definition added to such a table is equivalent to what is shown here:
my_row_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT INVISIBLE PRIMARY KEY
GIPK mode is not enabled by default. To enable it, set thesql_generate_invisible_primary_key server system variable to ON
.
Generated invisible primary keys are normally visible in the output of statements such as SHOW CREATE TABLE and SHOW INDEX, as well as in MySQL Information Schema tables such as the COLUMNS andSTATISTICS tables. You can cause them to be hidden in such cases instead, by settingshow_gipk_in_create_table_and_information_schema to OFF
.
As part of this work, a new--skip-generated-invisible-primary-key
option is added to mysqldump andmysqlpump to exclude generated invisible primary keys, columns, and column values from their output.
GIPKs and replication between tables with or without primary keys. In MySQL Replication, a replica effectively ignores any setting forsql_generate_invisible_primary_key on the source, such that it has no effect on replicated tables. MySQL 8.0.32 and later makes it possible for the replica to add a generated invisible primary key to anyInnoDB table that otherwise, as replicated, has no primary key. You can do this by invokingCHANGE REPLICATION SOURCE TO ... REQUIRE_TABLE_PRIMARY_KEY_CHECK = GENERATE on the replica.REQUIRE_TABLE_PRIMARY_KEY_CHECK = GENERATE
is not compatible with MySQL Group Replication.
For further information, seeSection 15.1.20.11, “Generated Invisible Primary Keys”.
- Crash-safe XA transactions. Previously, XA transactions were not fully resilient to an unexpected halt with respect to the binary log, and if this occurred while the server was executingXA PREPARE,
XA COMMIT
, orXA ROLLBACK
, the server was not guaranteed to be recoverable to the correct state, possibly leaving the binary log with extra XA transactions that had not been applied, or missing one or more XA transactions that had been applied. Beginning with MySQL 8.0.30, this is no longer an issue, and a server that drops out of a replication topology for whatever reason can always be brought back to a consistent XA transaction state when rejoining.
Known issue: When the same transaction XID is used to execute XA transactions sequentially and a break occurs during the execution ofXA COMMIT ... ONE PHASE
, using this same XID, after this transaction has been prepared in the storage engine, it may not be possible any longer to synchronize the state between the binary log and the storage engine.
For more information, see Section 15.3.8.3, “Restrictions on XA Transactions”. - Nesting with UNION. Beginning with MySQL 8.0.31, bodies of parenthesized query expressions can be nested up to 63 levels deep in combination with UNION. Such queries were previously rejected with errorER_NOT_SUPPORTED_YET, but are now allowed. EXPLAIN output for such a query is shown here:
mysql> EXPLAIN FORMAT=TREE (
-> (SELECT a, b, c FROM t ORDER BY a LIMIT 3) ORDER BY b LIMIT 2
-> ) ORDER BY c LIMIT 1\G
*************************** 1. row ***************************
EXPLAIN: -> Limit: 1 row(s) (cost=5.55..5.55 rows=1)
-> Sort: c, limit input to 1 row(s) per chunk (cost=2.50 rows=0)
-> Table scan on <result temporary> (cost=2.50 rows=0)
-> Temporary table (cost=5.55..5.55 rows=1)
-> Limit: 2 row(s) (cost=2.95..2.95 rows=1)
-> Sort: b, limit input to 2 row(s) per chunk (cost=2.50 rows=0)
-> Table scan on <result temporary> (cost=2.50 rows=0)
-> Temporary table (cost=2.95..2.95 rows=1)
-> Limit: 3 row(s) (cost=0.35 rows=1)
-> Sort: t.a, limit input to 3 row(s) per chunk (cost=0.35 rows=1)
-> Table scan on t (cost=0.35 rows=1)
1 row in set (0.00 sec)
MySQL follows SQL standard semantics when collapsing bodies of parenthesized query expressions, so that a higher outer limit cannot override an inner lower one. For example,(SELECT ... LIMIT 5) LIMIT 10
can return no more than five rows.
The 63-level limit is imposed only after the MySQL Optimizer's parser has performed any simplifications or merges which it can.
For more information, seeSection 15.2.11, “Parenthesized Query Expressions”.
- Disabling query rewrites. Previously, when using the
Rewriter
plugin, all queries were subject to being rewritten, regardless of user. This could be problematic in certain cases, such as when administering the system, or when applying statements originating from a replication source or a dump file created by mysqldump or another MySQL program. MySQL 8.0.31 provides a solution to such issues by implementing a new user privilegeSKIP_QUERY_REWRITE; statements issued by a user having this privilege are ignored byRewriter
and not rewritten.
MySQL 8.0.31 also adds a new server system variablerewriter_enabled_for_threads_without_privilege_checks. When set toOFF
, rewritable statements issued by threads for whichPRIVILEGE_CHECKS_USER
isNULL
(such as replication applier threads) are not rewritten by theRewriter
plugin. The default isON
, which means such statements are rewritten.
For more information, seeSection 7.6.4, “The Rewriter Query Rewrite Plugin”. - Replication filtering of XA statements. Previously, the statementsXA START,
XA END
,XA COMMIT
, andXA ROLLBACK
were filtered by the default database whenever using--replicate-do-db or--replicate-ignore-db, which could lead to missed transactions. As of MySQL 8.0.31, these statements are not filtered in such cases, regardless of the value ofbinlog_format. - Replication filtering and privilege checks. Beginning with MySQL 8.0.31, when replication filtering is in use, a replica no longer raises replication errors related to privilege checks orrequire_row_format validation for events which are filtered out, making it possible to filter out any transactions that fail validation.
Because privilege checks on filtered rows can no longer cause replication to stop, a replica can now accept only the portion of a database to which a given user has been granted access; this is true as long as updates to this part of the database are replicated only in row-based format.
This capability may also be of use when migrating to HeatWave Service from an on-premise or cloud service which uses tables for administration or other purposes to which the inbound replication user does not have access.
For more information, seeSection 19.2.5, “How Servers Evaluate Replication Filtering Rules”, as well asSection 19.5.1.29, “Replica Errors During Replication”. - INTERSECT and EXCEPT table operators. MySQL 8.0.31 adds support for the SQLINTERSECT andEXCEPT table operators. Where
a
and_b
_ represent result sets of queries, these operators behave as follows:_`a`_ INTERSECT_`b`_
includes only rows appearing in both result sets_a
_ and_b
_._`a`_ EXCEPT_`b`_
returns only those rows from result seta
which do not also appear in_b
_.INTERSECT DISTINCT
,INTERSECT ALL
,EXCEPT DISTINCT
, andEXCEPT ALL
are all supported;DISTINCT
is the default for bothINTERSECT
andEXCEPT
(this is the same as forUNION).
For more information and examples, seeSection 15.2.8, “INTERSECT Clause”, and Section 15.2.4, “EXCEPT Clause”.
- User-defined histograms. Beginning with MySQL 8.0.31, it is possible to set the histogram of a column to a user-specified JSON value. This can be done using the following SQL syntax:
ANALYZE TABLE tbl_name
UPDATE HISTOGRAM ON col_name
USING DATA 'json_data'
This statement creates or overwrites a histogram for column_colname
_ of table_tblname
_ using the histogram's JSON representation_jsondata
_. After executing this statement, you can verify that the histogram was created or updated by querying the Information SchemaCOLUMN_STATISTICS table, like this:
SELECT HISTOGRAM FROM INFORMATION_SCHEMA.COLUMN_STATISTICS
WHERE TABLE_NAME='tbl_name'
AND COLUMN_NAME='col_name';
The column value returned should be the same_jsondata
_ used in the previousANALYZE TABLE
statement.
This can be of use in cases where values deemed important are missed by the histogram sampling process. When this happens, you may want to modify the histogram or set your own histogram based on the complete data set. In addition, sampling a large user data set and building a histogram from it are resource-heavy operations which can impact user queries. With this enhancement, histogram generation can be moved off the (primary) server and performed on a replica instead; the generated histograms can then be assigned to the proper table columns on the source server.
For more information and examples, seeHistogram Statistics Analysis.
- Server build ID (Linux). MySQL 8.0.31 adds the read-onlybuild_id system variable for Linux systems, where a 160-bit
SHA1
signature is generated at compile time; the value ofbuild_id
is that of the generated value converted to a hexadecimal string, providing a unique identifier for the build.build_id
is written to the server log each time MySQL starts.
If you build MySQL from source, you can observe that this value changes each time you recompile the server. SeeSection 2.8, “Installing MySQL from Source”, for more information.
This variable is not supported on platforms other than Linux. - Default EXPLAIN output format. MySQL 8.0.32 adds a system variableexplain_format which determines the format of the output from anEXPLAIN statement used to obtain a query execution plan in the absence of any
FORMAT
option. For example, if the value ofexplain_format
isTREE
, then the output from any suchEXPLAIN
uses the tree-like format, just as if the statement had specifiedFORMAT=TREE
.
This behavior is overridden by the value set in aFORMAT
option. Suppose that_explainformat
_ is set to_TREE
_; even so,EXPLAIN FORMAT=JSON _`stmt`_
displays the result using the JSON output format.
For more information and examples, see the description of the explain_format system variable, as well asObtaining Execution Plan Information. There are also implications for the behavior ofEXPLAIN ANALYZE
; see Obtaining Information with EXPLAIN ANALYZE. - ST_TRANSFORM() Cartesian SRS support. Prior to MySQL 8.0.30, theST_TRANSFORM() function did not support Cartesian Spatial Reference Systems. In MySQL 8.0.30 and later, this function provides support for the Popular Visualisation Pseudo Mercator (EPSG 1024) projection method, used for WGS 84 Pseudo-Mercator (SRID 3857). MySQL 8.0.32 and later supports all Cartesian SRSs, except for EPSG 1042, EPSG 1043, EPSG 9816, and EPSG 9826.
- mysql client --system-command option. The --system-command option for the mysql client, available in MySQL 8.0.40 and later, enables or disables the
system
command.
This option is enabled by default. To disable it, use--system-command=OFF or--skip-system-command, which causes thesystem
command to be rejected with an error.