A first look at MariaDB 11.x features
and ideas on how to use them
Catalogs
● Not yet released
● In MariaDB, databases and schemas are the same thing
○ SCHEMA, SCHEMAS are synonyms for DATABASE,
DATABASES
● Both are similar to what other DBMSs call schemas:
namespaces, soft containers
Catalogs
● Both are similar to what other DBMSs call schemas:
namespaces, soft containers
● They also use different directories
● But the same connection can query multiple schemas and
join tables in different schemas
Catalogs
● Catalogs are similar to other DBMSs databases
● They provide isolation
● MDEV-31542
Catalogs
● Development databases are usually on the developers
laptops
● This has drawbacks, but having a DB in the cloud for each
developer would cost too much
● But with Catalogs, we can setup a Catalog for each
developers, for a reasonable cost
Catalogs for development databases
Catalogs for development databases
● Ideally, each microservice should run on a separate set of
servers, with Galera Cluster and/or replication
○ and a load balancer and monitoring and backups and …
● For microservices with a very low workload, this is too
expensive
● So, put them into the same servers / clusters, but at least use
Catalogs to provide more isolation
Catalogs for small microservices
Catalogs for small microservices
Migrations
● Since 11.2 most ALTER TABLEs are not locking
● Unless we specify different LOCK!=NONE or
ALGORITHM!=COPY clauses
● MDEV-26137
ALTER TABLE ONLINE
● Internally, it works similarly to gh-ost or
pt-online-schema-change:
○ A new table is created, with the required structure
○ The old table is still used
○ The new table is kept in sync with the old
○ Data are copied without locks
○ The tables are switched
ALTER TABLE ONLINE
InnoDB
● Change buffer was removed in 10.11,
but it was already disabled by default
● Fragmentation was removed in 11.1
InnoDB: cleanups
● After tables are dropped or many data are deleted, InnoDB
system tablespace will shrink are restart
MDEV-14795
● It's possible to shrink InnoDB temporary tablespace on
restart in this way:
SET innodb_truncate_temporary_tablespace_now = 1;
MDEV-28699
Note: local temporary tables now appear in
information_schema.TABLES
ALTER TABLE ONLINE
Security
Since MariaDB 11.3:
● SSL is now configured automatically
○ If a certificate exists it will be used
○ Otherwise a self-signed certificate is generated
● The client requires the server to use SSL by default
● Optionally, the client can verify server's certificate
SSL
● A self-signed certificate can be used to established encrypted
connections
● But it's not validated by a trusted Certification Authority
● This exposes you to man-in-the-middle attacks
● But for non-public server, a self-signed certificate is often
considered enough
SSL
● initialisation vector
Wikipedia: initialization vector
● block encryption mode
default: block_encryption_mode
https://www.highgo.ca/2019/08/08/the-difference-in-five-modes-in-the-aes-
encryption-algorithm/
AES
● New function KDF() returns good keys for AES_ENCRYPT()
● It uses OpenSSL EVP_KDF_derive()
SET @str = 'my secret';
SET @key = KDF('foo', 'bar', 'infa', 'hkdf');
SELECT HEX(
AES_ENCRYPT(@secret, '@key,
'0123456789abcdef',
'aes-256-cbc')
);
AES
● The key and the initialisation vector are necessary to decrypt
a string
● Storing them in the same database as the encrypted string is
a security risk
AES
Optimiser
● 11.x comes with big changes for the optimizer cost model
● This is a massive change, and would deserve a separate
webinar
Optimiser
● There are also cases when previously indexes couldn't be
used, but now can (some of these are in 10.11 as well):
○ WHERE DATE(col) = ?
○ WHERE YEAR(col) = ?
○ WHERE UPPER(col) = ?
○ WHERE utf8mb3_column = 'utf8mb4 string'
Optimiser
● Previously, subqueries were poorly optimised
DELETE
FROM user
WHERE id IN (SELECT id FROM user WHERE age < 18);
DELETEs and UPDATEs with subqueries
● information_schema.PROCESSLIST now has
ROWS_EXAMINED and SENT_ROWS columns
● This allows us to:
○ Check if a long query is returning many rows or is just a
poorly optimised query
○ Or monitor the processlist to find non-optimised queries,
prioritising those with a low sent / examined ratio
Processlist
Miscellaneous
● SET GLOBAL redirect_url = '...';
● Support from clients is needed
Redirection
Use cases:
● Dismiss a replica, inform clients to use another replica
instead
● Put replicas in maintenance
● Rolling upgrade
But you should use a proxy. So, a better use case is:
● Inform a proxies in advance that a replica shouldn't be used
Redirection
These options now are also variables:
● binlog_do_db
● binlog_ignore_db
● binlog_row_event_max_size
Redirection
SQL
● Validate JSON against JSON Schema, 2020 draft:
JSON_SCHEMA_VALID(schema, json);
● The schema is passed as a parameter
● In very simple cases, you can do this in a CHECK clause
● For more complex cases, store schema/schemas in a table
and use a chron
JSON_SCHEMA_VALID()
FORMAT_PICO_TIME(picoseconds)
Returns a human-readable string from picoseconds (10−12
)
Example: '2us' (microseconds)
ps - picoseconds
ns - nanoseconds
us - microseconds
ms - milliseconds
s - seconds
min - minutes
h - hours
d - days
FORMAT_PICO_TIME()
● JSON_OBJECT_FILTER_KEYS(obj, array_keys)
Returns an object with only the keys that are in the array
● JSON_OBJECT_TO_ARRAY(obj)
Transforms an object into an array in the form:
[ ["key1", "value1"], … ]
● JSON_ARRAY_INTERSECT(array1, array2)
Returns the intersection of 2 arrays
MDEV-26182
More JSON functions
● INET4 can now be cast into INET6
● This means that we can use queries like:
WHERE inet4_column = 'inet6 value'
IP types
A first look at MariaDB 11.x features and ideas on how to use them

A first look at MariaDB 11.x features and ideas on how to use them

  • 1.
    A first lookat MariaDB 11.x features and ideas on how to use them
  • 2.
  • 3.
    ● Not yetreleased ● In MariaDB, databases and schemas are the same thing ○ SCHEMA, SCHEMAS are synonyms for DATABASE, DATABASES ● Both are similar to what other DBMSs call schemas: namespaces, soft containers Catalogs
  • 4.
    ● Both aresimilar to what other DBMSs call schemas: namespaces, soft containers ● They also use different directories ● But the same connection can query multiple schemas and join tables in different schemas Catalogs
  • 5.
    ● Catalogs aresimilar to other DBMSs databases ● They provide isolation ● MDEV-31542 Catalogs
  • 6.
    ● Development databasesare usually on the developers laptops ● This has drawbacks, but having a DB in the cloud for each developer would cost too much ● But with Catalogs, we can setup a Catalog for each developers, for a reasonable cost Catalogs for development databases
  • 7.
  • 8.
    ● Ideally, eachmicroservice should run on a separate set of servers, with Galera Cluster and/or replication ○ and a load balancer and monitoring and backups and … ● For microservices with a very low workload, this is too expensive ● So, put them into the same servers / clusters, but at least use Catalogs to provide more isolation Catalogs for small microservices
  • 9.
    Catalogs for smallmicroservices
  • 10.
  • 11.
    ● Since 11.2most ALTER TABLEs are not locking ● Unless we specify different LOCK!=NONE or ALGORITHM!=COPY clauses ● MDEV-26137 ALTER TABLE ONLINE
  • 12.
    ● Internally, itworks similarly to gh-ost or pt-online-schema-change: ○ A new table is created, with the required structure ○ The old table is still used ○ The new table is kept in sync with the old ○ Data are copied without locks ○ The tables are switched ALTER TABLE ONLINE
  • 13.
  • 14.
    ● Change bufferwas removed in 10.11, but it was already disabled by default ● Fragmentation was removed in 11.1 InnoDB: cleanups
  • 15.
    ● After tablesare dropped or many data are deleted, InnoDB system tablespace will shrink are restart MDEV-14795 ● It's possible to shrink InnoDB temporary tablespace on restart in this way: SET innodb_truncate_temporary_tablespace_now = 1; MDEV-28699 Note: local temporary tables now appear in information_schema.TABLES ALTER TABLE ONLINE
  • 16.
  • 17.
    Since MariaDB 11.3: ●SSL is now configured automatically ○ If a certificate exists it will be used ○ Otherwise a self-signed certificate is generated ● The client requires the server to use SSL by default ● Optionally, the client can verify server's certificate SSL
  • 18.
    ● A self-signedcertificate can be used to established encrypted connections ● But it's not validated by a trusted Certification Authority ● This exposes you to man-in-the-middle attacks ● But for non-public server, a self-signed certificate is often considered enough SSL
  • 19.
    ● initialisation vector Wikipedia:initialization vector ● block encryption mode default: block_encryption_mode https://www.highgo.ca/2019/08/08/the-difference-in-five-modes-in-the-aes- encryption-algorithm/ AES
  • 20.
    ● New functionKDF() returns good keys for AES_ENCRYPT() ● It uses OpenSSL EVP_KDF_derive() SET @str = 'my secret'; SET @key = KDF('foo', 'bar', 'infa', 'hkdf'); SELECT HEX( AES_ENCRYPT(@secret, '@key, '0123456789abcdef', 'aes-256-cbc') ); AES
  • 21.
    ● The keyand the initialisation vector are necessary to decrypt a string ● Storing them in the same database as the encrypted string is a security risk AES
  • 22.
  • 23.
    ● 11.x comeswith big changes for the optimizer cost model ● This is a massive change, and would deserve a separate webinar Optimiser
  • 24.
    ● There arealso cases when previously indexes couldn't be used, but now can (some of these are in 10.11 as well): ○ WHERE DATE(col) = ? ○ WHERE YEAR(col) = ? ○ WHERE UPPER(col) = ? ○ WHERE utf8mb3_column = 'utf8mb4 string' Optimiser
  • 25.
    ● Previously, subquerieswere poorly optimised DELETE FROM user WHERE id IN (SELECT id FROM user WHERE age < 18); DELETEs and UPDATEs with subqueries
  • 26.
    ● information_schema.PROCESSLIST nowhas ROWS_EXAMINED and SENT_ROWS columns ● This allows us to: ○ Check if a long query is returning many rows or is just a poorly optimised query ○ Or monitor the processlist to find non-optimised queries, prioritising those with a low sent / examined ratio Processlist
  • 27.
  • 28.
    ● SET GLOBALredirect_url = '...'; ● Support from clients is needed Redirection
  • 29.
    Use cases: ● Dismissa replica, inform clients to use another replica instead ● Put replicas in maintenance ● Rolling upgrade But you should use a proxy. So, a better use case is: ● Inform a proxies in advance that a replica shouldn't be used Redirection
  • 30.
    These options noware also variables: ● binlog_do_db ● binlog_ignore_db ● binlog_row_event_max_size Redirection
  • 31.
  • 32.
    ● Validate JSONagainst JSON Schema, 2020 draft: JSON_SCHEMA_VALID(schema, json); ● The schema is passed as a parameter ● In very simple cases, you can do this in a CHECK clause ● For more complex cases, store schema/schemas in a table and use a chron JSON_SCHEMA_VALID()
  • 33.
    FORMAT_PICO_TIME(picoseconds) Returns a human-readablestring from picoseconds (10−12 ) Example: '2us' (microseconds) ps - picoseconds ns - nanoseconds us - microseconds ms - milliseconds s - seconds min - minutes h - hours d - days FORMAT_PICO_TIME()
  • 34.
    ● JSON_OBJECT_FILTER_KEYS(obj, array_keys) Returnsan object with only the keys that are in the array ● JSON_OBJECT_TO_ARRAY(obj) Transforms an object into an array in the form: [ ["key1", "value1"], … ] ● JSON_ARRAY_INTERSECT(array1, array2) Returns the intersection of 2 arrays MDEV-26182 More JSON functions
  • 35.
    ● INET4 cannow be cast into INET6 ● This means that we can use queries like: WHERE inet4_column = 'inet6 value' IP types