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 Jul 14, 2022
1 parent 411c0f1 commit 3b1d04e
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 @@ -1221,6 +1221,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 @@ -1336,8 +1337,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 3b1d04e

Please sign in to comment.