Repository navigation
Conversation
|
Denis Vidyaev seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
mysql table function to take user's SELECT subquery as an argument
… StorageMySQL interface
mysql table function to take user's SELECT subquery as an argument|
Dear @the-devid, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
7 similar comments
|
Dear @the-devid, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @the-devid, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @the-devid, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @the-devid, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @the-devid, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @the-devid, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @the-devid, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
…e integrations Generalizes the idea of ClickHouse#79652 (which added it for `mysql`) to all native SQL external-database integrations: `mysql`, `postgresql` and `sqlite`, both as table functions and as table engines. Instead of a remote table name, the table argument can now be a `SELECT` query that is passed to the external database as is, written either as a subquery `(SELECT ...)` or wrapped into `query('SELECT ...')`: SELECT * FROM mysql('host:3306', 'db', query('SELECT a, b FROM t WHERE a > 0'), 'user', 'pw'); SELECT * FROM postgresql('host:5432', 'db', (SELECT a, b FROM t WHERE a > 0), 'user', 'pw'); SELECT * FROM sqlite('db.sqlite', query('SELECT a, b FROM t')); This is useful to push down joins, aggregations and arbitrary processing to the external database. The structure of such a table is inferred from the query result; the table is read-only and `INSERT` into it throws `INCORRECT_QUERY`. Implementation: - New shared `TableNameOrQuery` abstraction (`src/Storages/TableNameOrQuery.h/.cpp`) holding either a table name or a query, plus the argument parser `tryGetExternalDatabaseQuery` and the read-projection builder `buildQueryForExternalDatabaseSubquery`. - MySQL: new `convertMySQLDataType(MYSQL_FIELD &)` overload and `mysqlxx::ResultBase::getField`; the structure is inferred by running the query with `LIMIT 0`. - PostgreSQL: `convertPostgreSQLDataType` is exposed; the structure is inferred from the result column OIDs of `SELECT * FROM (<query>) AS __subquery LIMIT 0` executed in a read-only transaction (works against read-only replicas as well). - SQLite: `convertSQLiteDataType` is exposed; the structure is inferred from the prepared statement's column metadata. Tests: a stateless test for `sqlite` and integration tests for `mysql` and `postgresql`. Docs updated for the three table functions. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Query forwarding to external databases (ClickHouse#107740) is based on Denis Vidiaev's ClickHouse#79652, the GeoJSON output format (ClickHouse#108065) on Mark Needham's ClickHouse#98124, and SZ3 (ClickHouse#108788) revives Konstantin Vedernikov's ClickHouse#83088. Co-Authored-By: Claude Fable 5 <[email protected]>
…e integrations Generalizes the idea of ClickHouse#79652 (which added it for `mysql`) to all native SQL external-database integrations: `mysql`, `postgresql` and `sqlite`, both as table functions and as table engines. Instead of a remote table name, the table argument can now be a `SELECT` query that is passed to the external database as is, written either as a subquery `(SELECT ...)` or wrapped into `query('SELECT ...')`: SELECT * FROM mysql('host:3306', 'db', query('SELECT a, b FROM t WHERE a > 0'), 'user', 'pw'); SELECT * FROM postgresql('host:5432', 'db', (SELECT a, b FROM t WHERE a > 0), 'user', 'pw'); SELECT * FROM sqlite('db.sqlite', query('SELECT a, b FROM t')); This is useful to push down joins, aggregations and arbitrary processing to the external database. The structure of such a table is inferred from the query result; the table is read-only and `INSERT` into it throws `INCORRECT_QUERY`. Implementation: - New shared `TableNameOrQuery` abstraction (`src/Storages/TableNameOrQuery.h/.cpp`) holding either a table name or a query, plus the argument parser `tryGetExternalDatabaseQuery` and the read-projection builder `buildQueryForExternalDatabaseSubquery`. - MySQL: new `convertMySQLDataType(MYSQL_FIELD &)` overload and `mysqlxx::ResultBase::getField`; the structure is inferred by running the query with `LIMIT 0`. - PostgreSQL: `convertPostgreSQLDataType` is exposed; the structure is inferred from the result column OIDs of `SELECT * FROM (<query>) AS __subquery LIMIT 0` executed in a read-only transaction (works against read-only replicas as well). - SQLite: `convertSQLiteDataType` is exposed; the structure is inferred from the prepared statement's column metadata. Tests: a stateless test for `sqlite` and integration tests for `mysql` and `postgresql`. Docs updated for the three table functions. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add suport for table function
mysqland table engineMySQLto take a user's query as an argument and pass it to the MySQL as is.Documentation entry for user-facing changes