Skip to content

Commit

Permalink
sql/schemachange: limit CTAS size
Browse files Browse the repository at this point in the history
Previously, the schemachange workload could generate
pretty large tables because of joins on CTAS statements.
These could take a fairly long time to CREATE. To address,
this patch will limit the maximum number of rows in
these tables.

Release note: None
  • Loading branch information
fqazi committed Aug 9, 2022
1 parent 867a8eb commit c0cc772
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@ func (og *operationGenerator) createEnum(ctx context.Context, tx pgx.Tx) (*opStm
}

func (og *operationGenerator) createTableAs(ctx context.Context, tx pgx.Tx) (*opStmt, error) {
const MaxRowsToConsume = 300000
numSourceTables := og.randIntn(og.params.maxSourceTables) + 1

sourceTableNames := make([]tree.TableExpr, numSourceTables)
Expand Down Expand Up @@ -1339,8 +1340,8 @@ func (og *operationGenerator) createTableAs(ctx context.Context, tx pgx.Tx) (*op
{code: pgcode.DuplicateColumn, condition: duplicateColumns},
}.add(opStmt.expectedExecErrors)

opStmt.sql = fmt.Sprintf(`CREATE TABLE %s AS %s`,
destTableName, selectStatement.String())
opStmt.sql = fmt.Sprintf(`CREATE TABLE %s AS %s FETCH FIRST %d ROWS ONLY`,
destTableName, selectStatement.String(), MaxRowsToConsume)
return opStmt, nil
}

Expand Down

0 comments on commit c0cc772

Please sign in to comment.