Skip to main content
Beta feature Advice on use of Beta features The database supports JDBC catalogs from v3.0 onwards. A JDBC catalog is a kind of external catalog that enables you to query data from data sources accessed through JDBC without ingestion. Also, you can directly transform and load data from JDBC data sources by using INSERT INTO based on JDBC catalogs. JDBC catalogs support MySQL and PostgreSQL from v3.0 onwards, Oracle and SQLServer since v3.2.9 and v3.3.1, and ClickHouse (Experimental) since v3.3.0.

Prerequisites

  • The FEs and BEs or CNs in your cluster can download the JDBC driver from the download URL specified by the driver_url parameter.
  • JAVA_HOME in the $BE_HOME/bin/start_be.sh file on each BE or CN node is properly configured as a path in the JDK environment instead of a path in the JRE environment. For example, you can configure export JAVA_HOME = <JDK_absolute_path>. You must add this configuration at the beginning of the script and restart the BE or CN for the configuration to take effect.

Create a JDBC catalog

Syntax

Parameters

catalog_name

The name of the JDBC catalog. The naming conventions are as follows:
  • The name can contain letters, digits (0-9), and underscores (_). It must start with a letter.
  • The name is case-sensitive and cannot exceed 1023 characters in length.

comment

The description of the JDBC catalog. This parameter is optional.

PROPERTIES

The properties of the JDBC Catalog. PROPERTIES must include the following parameters:

Optional Oracle properties

When driver_class is set to Oracle, you can configure the following optional properties:

Optional row-count cache properties

The database caches per-table row counts from JDBC sources to avoid blocking query planning. These properties let you tune the cache behavior per catalog. If not set, the global FE configuration values are used.
NOTE The FEs download the JDBC driver JAR package at the time of JDBC catalog creation, and the BEs or CNs download the JDBC driver JAR package at the time of the first query. The amount of time taken for the download varies depending on network conditions.

Examples

The following example creates five different JDBC catalogs.

View JDBC catalogs

You can use SHOW CATALOGS to query all catalogs in the current cluster:
You can also use SHOW CREATE CATALOG to query the creation statement of an external catalog. The following example queries the creation statement of a JDBC catalog named jdbc0:

Drop a JDBC catalog

You can use DROP CATALOG to drop a JDBC catalog. The following example drops a JDBC catalog named jdbc0:

Query a table in a JDBC catalog

  1. Use SHOW DATABASES to view the databases in your JDBC-compatible cluster:
  2. Use SET CATALOG to switch to the destination catalog in the current session:
    Then, use USE to specify the active database in the current session:
    Or, you can use USE to directly specify the active database in the destination catalog:
  3. Use SELECT to query the destination table in the specified database:

Join pushdown

From v4.2 onwards, the system can push multi-table joins (both INNER JOIN and CROSS JOIN) down to the external database when all joined tables come from the same JDBC catalog. This lets the source database execute the join using its own indexes and optimizer, and returns only the joined result back to the system.

Configure join pushdown

Join pushdown is enabled by default. Set the session variable enable_jdbc_join_push_down to false to disable it:

How it works

When the rule fires, the optimizer rewrites the local join over multiple JDBC scans into a single JDBC scan that issues one SQL query containing a JOIN against the remote database. For example, the following query against two MySQL tables in the same JDBC catalog:
When enable_jdbc_join_push_down is false, the system issues two separate scans and joins the result locally. When the variable is true, the whole join subtree is pushed down to the remote database. The local plan contains only one JDBC scan node, and the pushed-down SQL looks similar to:
Use EXPLAIN on a query to verify whether the join was pushed down.

Scope and limitations

  • Join type: INNER JOIN and CROSS JOIN are eligible for pushdown. Outer, semi, and anti joins fall back to local execution.
  • Same catalog: all tables in a merged group must belong to the same JDBC catalog (same JDBC URI, credentials, and driver). Joins that mix two JDBC catalogs, or that mix JDBC tables with native tables, run locally.
  • Cross-table predicate required: a group is pushed down only if it has at least one predicate that joins two tables in the group. Otherwise the rule skips it to avoid sending a pure cartesian product to the remote database.
  • All-or-nothing predicate pushdown: every predicate owned by a group must be fully translatable to the remote dialect. If any predicate cannot be pushed (for example, a StarRocks-only function), the whole group falls back to a local join.
  • Statistics: the merged JDBC scan reuses the same default statistics as a single-table JDBC scan. Downstream operators see the joined result as if it were one table of default size, and cardinality is not estimated from the underlying tables.

Query JDBC data with native SQL

From v4.1 onwards, the database supports querying JDBC data with database-native SELECT statements by using the native_query table function. native_query is useful when the source database must run SQL that cannot be expressed as a single external table query, such as source-side joins, pre-filtered subqueries, or vendor-specific SQL syntax. The database exposes the pass-through query result as a normal relation, so you can continue to apply StarRocks-side filters, joins, aggregations, and projections. For syntax, limitations, and examples, see native_query.

FAQ

What do I do if an error suggesting “Malformed database URL, failed to parse the main URL sections” is thrown? If you encounter such an error, the URI that you passed in jdbc_uri is invalid. Check the URI that you pass and make sure it is valid. For more information, see the parameter descriptions in the “PROPERTIES” section of this topic.