[MDEV-23023] Put compatibility functions and data types into namespaces Created: 2020-06-26 Updated: 2021-05-11 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Data types |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | Compatibility, sql_mode | ||
| Issue Links: |
|
||||||||
| Description |
|
This task proposes a simple and consistent way of handling compatibility modes, taking into account the SQL standard. It's intended to define implementation directions for:
(and other similar tasks and bug fixes) PreambleDifferent compatibility modes in MariaDB (e.g. sql_mode=DEFAULT vs sql_mode=ORACLE) translate function and data type names into different implementations. Examples:
The intent of this task is disambiguation: making it possible in any @@sql_mode to specify a certain implementation, independingly of the current @@sql_mode value. Proposed syntax for functions
Proposed syntax for data types
Implementations chosen by defaultThis statement:
will switch the order of funciton and data type lookup to: ORACLE,MARIADB. This statement:
will switch the order of function and data type lookup to: MARIADB,ORACLE (or just to MARIADB). Examples:
SQL Standard compatibilityQualified data types and funtions will just look like:
The proposed syntax for functions will resemble the SQL standard syntax for <schema qualified routine name>.
The proposed syntax for data types will resemble the SQL standard for user defined data types:
The idea is that predefined data types "belong" to the entire server, while qualified data types belong to a certain schema. From this point of view:
So schemas will naturally play role of namespaces. Data type and functions pluginsThe INSTALL PLUGIN statement for data type and function plugins (which were implemented in 10.5) will be extended to optionally specify the database to put the data type or the function to. By default, data type and function plugins will register "globally", like built-in types and functions. Compatibility databasesCompatibility databases, such as `oracle`, will be created at bootstrap time. Note, the highly requested Oracle package DBMS_OUTPUT (which will possibly be implemented in 10.6) will reside in the compatibility database `oracle`. The advantage of having compatibility namespaces as real databases on disk is that we'll be able to implement compatibility mode specific objects (like functions, procedures and data types) using any ways:
So for example the Oracle DECODE() can eventually become a function plugin or a stored function. Similar, the Oracle DATE can become a data type plugin, or a stored data type (when we implement the CREATE TYPE statement). The switch between a hardcoded implementation to a database-specific (data type or function) plugin or to a stored (data type or function) object will be very simple for users: syntactically nothing will change on the SQL level. Database `mariadb`The database `mariadb`, unlike real compatbility databases, does not need any entries in its tables to "register" built-in data types or built-in functions. They can stay hard-coded in the server, as now. The order of lookupThe order of lookup in the first implementation will depend solely on the sql_mode value. So sql_mode=ORACLE will lookup up in the Oracle data types and functions first, then in MariaDB data types and functions. Later we can implement the SQL standard SET PATH statement, which will give more flexibility. SHOW and I_SStatements like:
will print qualified identifiers only when it is really necessary, to avoid polluting all dumps with the `mariadb.` qualifier for the built-in data types and functions. So,
will still print non-qualified data types and functions as before:
However, this script:
will still print qualified versions (in the data type `date` and in the function `decode`):
Note, `varchar` does not need a qualifier even in compatibility mode, because it refers to the regular MariaDB VARCHAR even in sql_mode=ORACLE. The exact compatibility database namesDatabase names `mariadb` and `oracle` are subject to a discussion. They can: Implementation planIn 10.5 we need to do only very simple changes: 1. Add the qualified syntax in the parser, to fix these (and similar) bugs:
2. Make the qualified syntax (in the hard-coded way) map as follows:
AdvantagesWhenever we implement a replacement data type or function, e.g. for sql_mode=ORACLE, we won't have to implement disambiguating aliases such as :
in sql_yacc.yy for every replaced data type TYPE and function FUNC. MariaDB data types and functions will always be available as MARIADB.TYPE and MARIADRIADB.FUNC() for any built-in data type and function. Oracle data types and functions will be installed as plugins or stored objects in the corresponding compatibility database `oracle`. So no changes in the main server code are needed at all to introduce an sql_mode specific replacement for a data type or a function. Eventually, we can add parser plugins (should be very easy to do). So a compatibility mode will just become a set of:
Open questionsWe could use `mysql` as a compatibility database (i.e. as a qualificator) for sql_mode=DEFAULT. But in this case we'll have to change the way how MYSQL.FUNC() calls are processed. For now it always calls a stored function. We'll have to allow to call built-in functions as well. It's not clear what should be the order of resolution. Should it lookup in built-in functions first, and in case of failure switch to SP? Users who already have stored function in the database `mysql` with names coinciding |