Skip to content

Commit a4bf0a9

Browse files
committed
Disable SET_UNLOGGED_LOGGED for partitioned table for PG18; Fix NPE for PostgresBinaryComparisonOperation
1 parent d7b272b commit a4bf0a9

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/sqlancer/postgres/PostgresSchema.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,26 @@ public enum TableType {
164164
private final TableType tableType;
165165
private final List<PostgresStatisticsObject> statistics;
166166
private final boolean isInsertable;
167+
private final boolean isPartitioned;
167168

168169
public PostgresTable(String tableName, List<PostgresColumn> columns, List<PostgresIndex> indexes,
169170
TableType tableType, List<PostgresStatisticsObject> statistics, boolean isView, boolean isInsertable) {
170171
super(tableName, columns, indexes, isView);
171172
this.statistics = statistics;
172173
this.isInsertable = isInsertable;
173174
this.tableType = tableType;
175+
//TODO: simple adapter for other implementations
176+
this.isPartitioned = false;
177+
}
178+
179+
public PostgresTable(String tableName, List<PostgresColumn> columns, List<PostgresIndex> indexes,
180+
TableType tableType, List<PostgresStatisticsObject> statistics, boolean isView, boolean isInsertable,
181+
boolean isPartitioned) {
182+
super(tableName, columns, indexes, isView);
183+
this.statistics = statistics;
184+
this.isInsertable = isInsertable;
185+
this.tableType = tableType;
186+
this.isPartitioned = isPartitioned;
174187
}
175188

176189
public List<PostgresStatisticsObject> getStatistics() {
@@ -185,6 +198,10 @@ public boolean isInsertable() {
185198
return isInsertable;
186199
}
187200

201+
public boolean isPartitioned() {
202+
return isPartitioned;
203+
}
204+
188205
}
189206

190207
public static final class PostgresStatisticsObject {
@@ -225,11 +242,12 @@ public static PostgresSchema fromConnection(SQLConnection con, String databaseNa
225242
List<PostgresTable> databaseTables = new ArrayList<>();
226243
try (Statement s = con.createStatement()) {
227244
try (ResultSet rs = s.executeQuery(
228-
"SELECT table_name, table_schema, table_type, is_insertable_into FROM information_schema.tables WHERE table_schema='public' OR table_schema LIKE 'pg_temp_%' ORDER BY table_name;")) {
245+
"SELECT t.table_name, t.table_schema, t.table_type, t.is_insertable_into, c.relkind FROM information_schema.tables t JOIN pg_class c ON c.relname = t.table_name JOIN pg_namespace n ON n.oid = c.relnamespace AND n.nspname = t.table_schema WHERE t.table_schema='public' OR t.table_schema LIKE 'pg_temp_%' ORDER BY t.table_name;")) {
229246
while (rs.next()) {
230247
String tableName = rs.getString("table_name");
231248
String tableTypeSchema = rs.getString("table_schema");
232249
boolean isInsertable = rs.getBoolean("is_insertable_into");
250+
boolean isPartitioned = "p".equals(rs.getString("relkind"));
233251
// TODO: also check insertable
234252
// TODO: insert into view?
235253
boolean isView = tableName.startsWith("v"); // tableTypeStr.contains("VIEW") ||
@@ -240,7 +258,7 @@ public static PostgresSchema fromConnection(SQLConnection con, String databaseNa
240258
List<PostgresIndex> indexes = getIndexes(con, tableName);
241259
List<PostgresStatisticsObject> statistics = getStatistics(con);
242260
PostgresTable t = new PostgresTable(tableName, databaseColumns, indexes, tableType, statistics,
243-
isView, isInsertable);
261+
isView, isInsertable, isPartitioned);
244262
for (PostgresColumn c : databaseColumns) {
245263
c.setTable(t);
246264
}
@@ -324,4 +342,4 @@ public String getDatabaseName() {
324342
return databaseName;
325343
}
326344

327-
}
345+
}

src/sqlancer/postgres/ast/PostgresBinaryComparisonOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public PostgresConstant getExpectedValue() {
126126
PostgresConstant leftExpectedValue = getLeft().getExpectedValue();
127127
PostgresConstant rightExpectedValue = getRight().getExpectedValue();
128128
if (leftExpectedValue == null || rightExpectedValue == null) {
129-
return null;
129+
return PostgresConstant.createNullConstant();
130130
}
131131
return getOp().getExpectedValue(leftExpectedValue, rightExpectedValue);
132132
}

src/sqlancer/postgres/gen/PostgresAlterTableGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public List<Action> getActions(ExpectedErrors errors) {
127127
if (!randomTable.hasIndexes()) {
128128
action.remove(Action.ADD_TABLE_CONSTRAINT_USING_INDEX);
129129
}
130+
if (randomTable.isPartitioned()){
131+
action.remove(Action.SET_LOGGED_UNLOGGED);
132+
}
130133
if (action.isEmpty()) {
131134
throw new IgnoreMeException();
132135
}

0 commit comments

Comments
 (0)