Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude CockroachDB's hidden column from a catalog #351

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/main/java/com/oltpbenchmark/util/SQLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,6 @@ private static AbstractCatalog getCatalogDirect(DatabaseType databaseType, Conne

Map<String, Table> tables = new HashMap<>();

List<String> 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");
Copy link
Member

@apavlo apavlo Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't you just add crdb_internal_ here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the hidden columns to be excluded here must be determined using the startsWith() method, not the equals() method applied to each element of excludedColumns. excludeColumns is only used to exclude a hidden column rowid for CockroachDB.

Copy link
Contributor Author

@stonewhitener stonewhitener Sep 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, the DDL below generates a hidden column crdb_internal_ts_shard_20.

CREATE TABLE products (
    ts DECIMAL PRIMARY KEY USING HASH WITH (bucket_count = 20),
    product_id INT8
);

A suffix of a hidden column name is determined based on the primary key name and bucket size specified in the DDL. We can not exclude such columns by simply applying equals().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, what if we create a list of compiled regular expressions and then have it check that instead having separate logic for equals and startsWith.

}


try (ResultSet table_rs = md.getTables(catalog, schema, null, new String[]{"TABLE"})) {
while (table_rs.next()) {

Expand All @@ -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");
Expand Down