Skip to content

Commit f0c7eed

Browse files
Fix yugabyte tablegroups in colocated database (sqlancer#795)
* fix: yugabyte error: cannot use tablegroups in a colocated database * fix: delete useless import * fix: column index starts from 1 * fix: change check colocated logic when creating table * fix: add exception handle * style: check statement will not return an error * fix: remove useless null check * fix: PMD violation
1 parent 33e2865 commit f0c7eed

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/sqlancer/yugabyte/ysql/YSQLSchema.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ protected static List<YSQLColumn> getTableColumns(SQLConnection con, String tabl
160160
return columns;
161161
}
162162

163+
public boolean getDatabaseIsColocated(SQLConnection con) {
164+
try (Statement s = con.createStatement(); ResultSet rs = s.executeQuery("SELECT yb_is_database_colocated();")) {
165+
rs.next();
166+
String result = rs.getString(1);
167+
// The query will result in a 'f' for a non-colocated database
168+
return !"f".equals(result);
169+
170+
} catch (SQLException e) {
171+
throw new AssertionError(e);
172+
}
173+
}
174+
163175
public YSQLTables getRandomTableNonEmptyTables() {
164176
return new YSQLTables(Randomly.nonEmptySubset(getDatabaseTables()));
165177
}

src/sqlancer/yugabyte/ysql/gen/YSQLCommon.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ public static void generateWith(StringBuilder sb, YSQLGlobalState globalState, E
159159
}
160160
} else if (Randomly.getBoolean()) {
161161
errors.add("Cannot use TABLEGROUP with TEMP table");
162-
sb.append(" TABLEGROUP tg").append(
163-
Randomly.getNotCachedInteger(1, (int) YSQLTableGroupGenerator.UNIQUE_TABLEGROUP_COUNTER.get()));
162+
if (!globalState.getSchema().getDatabaseIsColocated(globalState.getConnection())) {
163+
sb.append(" TABLEGROUP tg").append(
164+
Randomly.getNotCachedInteger(1, (int) YSQLTableGroupGenerator.UNIQUE_TABLEGROUP_COUNTER.get()));
165+
}
164166
}
165167
}
166168

0 commit comments

Comments
 (0)