remapdb Database Remapping Hint¶
remapdb rewrites qualified database references from a source database to a target database in SELECT, DML, table DDL, and ANALYZE statements; it is gated by
enable_remap_hintand can be set per session or per query.
Description¶
remapdb is a database-name remapping rule used by the MatrixOne query rewrite feature. It maps a source database name to a target database name, so that a qualified reference such as source_db.table resolves to target_db.table.
The rule is supplied as a JSON object under the remapdb key and can be set in two ways:
As the value of the
remap_rewritessession variable, applying to every subsequent query in the session.As an inline
/*+ ... */hint, applying to the single query that carries it.
Both forms are gated by enable_remap_hint; when that variable is off, the rule is ignored.
Syntax¶
{"remapdb": {"source_database": "target_database", ...}}
SET remap_rewrites = '{"remapdb": {"source_database": "target_database"}}'
/*+ {"remapdb": {"source_database": "target_database"}} */ SELECT ...
Only qualified references are rewritten. USE is not remapped, but while the current database is a remap source, unqualified names resolve against the target database. remapdb is applied before the table rewrites rules.
Arguments¶
remapdb takes a single value: a JSON object under the remapdb key that maps source database names to target database names.
Examples¶
DROP DATABASE IF EXISTS remapdb_dst;
CREATE DATABASE remapdb_dst;
USE remapdb_dst;
DROP DATABASE IF EXISTS remapdb_src;
CREATE DATABASE remapdb_src;
CREATE TABLE remapdb_dst.t (id INT);
CREATE TABLE remapdb_src.t (id INT);
INSERT INTO remapdb_dst.t VALUES (1), (2), (3);
INSERT INTO remapdb_src.t VALUES (100), (200);
SET enable_remap_hint = 1;
SET remap_rewrites = '{"remapdb": {"remapdb_src": "remapdb_dst"}}';
SELECT * FROM remapdb_src.t ORDER BY id;
SET remap_rewrites = '';
SET enable_remap_hint = 0;
DROP DATABASE remapdb_src;
DROP DATABASE remapdb_dst;
Constraints¶
remapdbnames must be valid identifiers.The source and destination database sets must be disjoint; chaining (
atobandbtoc) and self-mapping are rejected.Multiple sources may map to the same destination.
System databases (
information_schema,mysql,system,system_metrics, and anymo_*database) cannot be used as either a source or a destination.Database-level DDL (
CREATE/DROP/ALTER DATABASE,USE) is never remapped.