Couple performance fixes: 1) cache the SQL schema for a table, and 2) only update output every 500 lines. Together these give us a 60% speedup on a large import.

Signed-off-by: Zach Musgrave <zach@liquidata.co>
This commit is contained in:
Zach Musgrave
2019-12-05 12:42:03 -08:00
parent b574e6c20c
commit fdf6ac4ac7
2 changed files with 27 additions and 16 deletions

View File

@@ -201,6 +201,8 @@ func runBatchMode(ctx context.Context, se *sqlEngine) error {
query = ""
}
updateBatchInsertOutput()
if err := scanner.Err(); err != nil {
cli.Println(err.Error())
}
@@ -472,6 +474,7 @@ var batchEditStats stats
var displayStrLen int
const maxBatchSize = 50000
const updateInterval = 500
// Processes a single query in batch mode. The Root of the sqlEngine may or may not be changed.
func processBatchQuery(ctx context.Context, query string, se *sqlEngine) error {
@@ -499,8 +502,9 @@ func processBatchQuery(ctx context.Context, query string, se *sqlEngine) error {
}
}
displayStr := fmt.Sprintf("Rows inserted: %d", batchEditStats.numRowsInserted)
displayStrLen = cli.DeleteAndPrint(displayStrLen, displayStr)
if batchEditStats.numRowsInserted%updateInterval == 0 {
updateBatchInsertOutput()
}
return nil
default:
@@ -520,6 +524,11 @@ func processBatchQuery(ctx context.Context, query string, se *sqlEngine) error {
}
}
func updateBatchInsertOutput() {
displayStr := fmt.Sprintf("Rows inserted: %d", batchEditStats.numRowsInserted)
displayStrLen = cli.DeleteAndPrint(displayStrLen, displayStr)
}
// Updates the batch insert stats with the results of an insert operation.
func mergeInsertResultIntoStats(rowIter sql.RowIter, s *stats) error {
for {

View File

@@ -30,11 +30,12 @@ import (
// DoltTable implements the sql.Table interface and gives access to dolt table rows and schema.
type DoltTable struct {
name string
table *doltdb.Table
sch schema.Schema
db *Database
ed *tableEditor
name string
table *doltdb.Table
sch schema.Schema
sqlSch sql.Schema
db *Database
ed *tableEditor
}
var _ sql.Table = (*DoltTable)(nil)
@@ -78,20 +79,21 @@ func (t *DoltTable) String() string {
// Schema returns the schema for this table.
func (t *DoltTable) Schema() sql.Schema {
// TODO: fix panics
sch, err := t.table.GetSchema(context.TODO())
if err != nil {
panic(err)
}
// TODO: fix panics
sqlSch, err := doltSchemaToSqlSchema(t.name, sch)
return t.sqlSchema()
}
func (t *DoltTable) sqlSchema() sql.Schema {
if t.sqlSch != nil {
return t.sqlSch
}
// TODO: fix panics
sqlSch, err := doltSchemaToSqlSchema(t.name, t.sch)
if err != nil {
panic(err)
}
t.sqlSch = sqlSch
return sqlSch
}