From 0e74e994c75cc7cf84acad8d10d9d1a4b971c38c Mon Sep 17 00:00:00 2001 From: Youki Shiraishi Date: Thu, 31 Aug 2023 03:25:57 +0200 Subject: [PATCH] Exclude CockroachDB's hidden columns from a catalog --- .../java/com/oltpbenchmark/util/SQLUtil.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/oltpbenchmark/util/SQLUtil.java b/src/main/java/com/oltpbenchmark/util/SQLUtil.java index 3471dda1b..a5869c276 100644 --- a/src/main/java/com/oltpbenchmark/util/SQLUtil.java +++ b/src/main/java/com/oltpbenchmark/util/SQLUtil.java @@ -512,14 +512,6 @@ private static AbstractCatalog getCatalogDirect(DatabaseType databaseType, Conne Map tables = new HashMap<>(); - List excludedColumns = new ArrayList<>(); - - if (databaseType.equals(DatabaseType.COCKROACHDB)) { - // cockroachdb has a hidden column called "ROWID" that should not be directly used via the catalog - excludedColumns.add("ROWID"); - } - - try (ResultSet table_rs = md.getTables(catalog, schema, null, new String[]{"TABLE"})) { while (table_rs.next()) { @@ -535,9 +527,15 @@ private static AbstractCatalog getCatalogDirect(DatabaseType databaseType, Conne while (col_rs.next()) { String col_name = col_rs.getString("COLUMN_NAME"); - if (excludedColumns.contains(col_name.toUpperCase())) { - LOG.debug("found excluded column [{}] for in database type [{}]. Skipping...", col_name, databaseType); - continue; + if (databaseType.equals(DatabaseType.COCKROACHDB)) { + if (col_name.equals("rowid") || col_name.startsWith("crdb_internal_")) { + // CockroachDB adds a hidden column called "rowid" or "crdb_internal_*" + // when a table is defined without a primary key or when a hash-sharded + // primary key is used, respectively, that should not be directly used + // via the catalog. + LOG.debug("found excluded column [{}] for in database type [{}]. Skipping...", col_name, databaseType); + continue; + } } int col_type = col_rs.getInt("DATA_TYPE");