Skip to content

jdbc-v2 tests: getTables without a schema scans every database on the server #3510

Description

@monosoul

Two jdbc-v2 integration tests call DatabaseMetaData#getTables with a null schema pattern. With jdbc_metadata_use_show_statements (the default), that sends one SHOW FULL TABLES per database, so the tests' time grows with the number of databases on the server. On the shared Cloud service (run 47116712695) they take about 8 of jdbc-v2's 15 minutes:

Test Call Cloud time
DatabaseMetaDataTest.testGetTables (SHOW-statement variants) getTables("system", null, "numbers", …): "system" is the catalog, which v2 ignores 183 s, 224 s
StatementTest.testEmptyFormatConfigurationBehavior getTables(null, null, "test_empty_format_tb", null) 74 s

Both tests check a table in one known database (system, and the connection's own), so they should pass it as the schema pattern. This also stops testGetTables's exactly-one-numbers assertion from depending on what the other databases contain.

Activity

  1. added
    tests
    jdbc
    jdbc-metadata
    on Dec 3, 2026
  2. self-assigned this
    on Dec 3, 2026
  3. polyglotAI-bot commented on Dec 3, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — fix needed
    Merge PR #3511: it moves both calls to one schema, and no other jdbc-v2 test calls getTables or getColumns with no schema. With its scope, the run sends 1 SHOW FULL TABLES query in place of 1 per database. It is approved, and its checks pass.

    • Category: Other
    • Classification: impact: none · area: Docs & project (jdbc-v2 tests)
    • Status on main: Reproduced on main — the call of testGetTables sends one SHOW FULL TABLES per database (25 of 25), and returns 2 rows when another database has a numbers table.
    • Breaking change: No — the change is in test code only.
    • Duplicates / related: Related: Cloud Tests: test databases are not cleaned up on the shared Cloud service #3508 — the test databases that pile up on the same Cloud service.

    Analysis: The root cause in the issue is correct: getTables ignores the catalog (DatabaseMetaDataImpl.java:1001-1008), and the SHOW path runs one SHOW FULL TABLES FROM <db> for each database that matches the schema pattern (ShowStatementsMetaData.java:195-197). The exactly-one assertion is DatabaseMetaDataTest.java:528: it fails when another database has a table named numbers.

    Reproduction: complete program and output
    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.Properties;
    
    public class Repro {
        static final String URL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
        static final String PASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
    
        static long scalar(Statement st, String sql) throws Exception {
            try (ResultSet rs = st.executeQuery(sql)) {
                rs.next();
                return rs.getLong(1);
            }
        }
    
        static long showTablesCount(Statement st) throws Exception {
            st.execute("SYSTEM FLUSH LOGS");
            return scalar(st, "SELECT count() FROM system.query_log WHERE type = 'QueryFinish' AND query LIKE 'SHOW FULL TABLES FROM%'");
        }
    
        static void run(String label, DatabaseMetaData md, Statement st, String catalog, String schema) throws Exception {
            long before = showTablesCount(st);
            int rows = 0;
            try (ResultSet rs = md.getTables(catalog, schema, "numbers", null)) {
                while (rs.next()) {
                    rows++;
                }
            }
            long queries = showTablesCount(st) - before;
            System.out.println(label + ": rows=" + rows + ", SHOW FULL TABLES queries=" + queries);
        }
    
        public static void main(String[] args) throws Exception {
            Properties props = new Properties();
            props.setProperty("user", "default");
            props.setProperty("password", PASSWORD);
            String jdbcUrl = "jdbc:clickhouse:" + URL.replaceFirst("^https?:", "") + "/default";
            try (Connection conn = DriverManager.getConnection(jdbcUrl, props);
                 Statement st = conn.createStatement()) {
                for (int i = 0; i < 20; i++) {
                    st.execute("CREATE DATABASE IF NOT EXISTS triage3510_db" + i);
                }
                st.execute("CREATE TABLE triage3510_db0.numbers (n UInt64) ENGINE = Memory");
                System.out.println("databases on the server: " + scalar(st, "SELECT count() FROM system.databases"));
                DatabaseMetaData md = conn.getMetaData();
                try {
                    run("getTables(\"system\", null, \"numbers\", null)", md, st, "system", null);
                    run("getTables(null, \"system\", \"numbers\", null)", md, st, null, "system");
                } catch (Exception e) {
                    System.out.println("error: " + e.getClass().getName() + ": " + e.getMessage());
                } finally {
                    for (int i = 0; i < 20; i++) {
                        st.execute("DROP DATABASE IF EXISTS triage3510_db" + i);
                    }
                }
            }
        }
    }

    Output on main (ea662722e), ClickHouse 26.11.7.10:

    databases on the server: 25
    getTables("system", null, "numbers", null): rows=2, SHOW FULL TABLES queries=25
    getTables(null, "system", "numbers", null): rows=1, SHOW FULL TABLES queries=1
    

    Automated triage by Polyglot AI. A maintainer makes the final decision.

  4. added
    ci
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cijdbcjdbc-metadatatests

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions