From d14753f00743bc729a57e17611c4acdfb9180817 Mon Sep 17 00:00:00 2001 From: marvin Date: Fri, 12 Jul 2024 10:33:06 +0800 Subject: [PATCH 1/2] perf memory --- query_column_add.go | 3 ++- query_column_drop.go | 3 ++- query_delete.go | 2 +- query_index_create.go | 2 +- query_index_drop.go | 2 +- query_insert.go | 2 +- query_merge.go | 2 +- query_select.go | 6 +++--- query_table_create.go | 2 +- query_table_drop.go | 2 +- query_table_truncate.go | 2 +- query_update.go | 2 +- 12 files changed, 16 insertions(+), 14 deletions(-) diff --git a/query_column_add.go b/query_column_add.go index 32a21338e..7baca8a35 100644 --- a/query_column_add.go +++ b/query_column_add.go @@ -118,7 +118,8 @@ func (q *AddColumnQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte //------------------------------------------------------------------------------ func (q *AddColumnQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Result, error) { - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + bytes := make([]byte, 0) + queryBytes, err := q.AppendQuery(q.db.fmter, bytes) if err != nil { return nil, err } diff --git a/query_column_drop.go b/query_column_drop.go index 1439ed9b9..c5de3d1ef 100644 --- a/query_column_drop.go +++ b/query_column_drop.go @@ -114,7 +114,8 @@ func (q *DropColumnQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byt //------------------------------------------------------------------------------ func (q *DropColumnQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Result, error) { - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + bytes := make([]byte, 0) + queryBytes, err := q.AppendQuery(q.db.fmter, bytes) if err != nil { return nil, err } diff --git a/query_delete.go b/query_delete.go index 49a750cc8..f93298dab 100644 --- a/query_delete.go +++ b/query_delete.go @@ -260,7 +260,7 @@ func (q *DeleteQuery) scanOrExec( } // Generate the query before checking hasReturning. - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_index_create.go b/query_index_create.go index 11824cfa4..f916e75e9 100644 --- a/query_index_create.go +++ b/query_index_create.go @@ -238,7 +238,7 @@ func (q *CreateIndexQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []by //------------------------------------------------------------------------------ func (q *CreateIndexQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Result, error) { - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_index_drop.go b/query_index_drop.go index ae28e7956..d50635382 100644 --- a/query_index_drop.go +++ b/query_index_drop.go @@ -105,7 +105,7 @@ func (q *DropIndexQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte //------------------------------------------------------------------------------ func (q *DropIndexQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Result, error) { - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_insert.go b/query_insert.go index 6d38a4efe..e879c7dd4 100644 --- a/query_insert.go +++ b/query_insert.go @@ -575,7 +575,7 @@ func (q *InsertQuery) scanOrExec( } // Generate the query before checking hasReturning. - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_merge.go b/query_merge.go index 626752b8a..57f0eb4e6 100644 --- a/query_merge.go +++ b/query_merge.go @@ -232,7 +232,7 @@ func (q *MergeQuery) scanOrExec( } // Generate the query before checking hasReturning. - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_select.go b/query_select.go index 932cd48be..d3c4217c0 100644 --- a/query_select.go +++ b/query_select.go @@ -807,7 +807,7 @@ func (q *SelectQuery) Rows(ctx context.Context) (*sql.Rows, error) { return nil, err } - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } @@ -828,7 +828,7 @@ func (q *SelectQuery) Exec(ctx context.Context, dest ...interface{}) (res sql.Re return nil, err } - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } @@ -875,7 +875,7 @@ func (q *SelectQuery) Scan(ctx context.Context, dest ...interface{}) error { return err } - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return err } diff --git a/query_table_create.go b/query_table_create.go index 3d98da07b..e189635ed 100644 --- a/query_table_create.go +++ b/query_table_create.go @@ -342,7 +342,7 @@ func (q *CreateTableQuery) Exec(ctx context.Context, dest ...interface{}) (sql.R return nil, err } - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_table_drop.go b/query_table_drop.go index e4447a8d2..29af74fa2 100644 --- a/query_table_drop.go +++ b/query_table_drop.go @@ -113,7 +113,7 @@ func (q *DropTableQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Res } } - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_table_truncate.go b/query_table_truncate.go index 9ac5599d9..9b27adca0 100644 --- a/query_table_truncate.go +++ b/query_table_truncate.go @@ -126,7 +126,7 @@ func (q *TruncateTableQuery) AppendQuery( //------------------------------------------------------------------------------ func (q *TruncateTableQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Result, error) { - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_update.go b/query_update.go index e56ba20d1..a8dafa526 100644 --- a/query_update.go +++ b/query_update.go @@ -506,7 +506,7 @@ func (q *UpdateQuery) scanOrExec( } // Generate the query before checking hasReturning. - queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes()) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } From d0eeb0ba5e0b32cc59d5ece2ee7a3568a39ed482 Mon Sep 17 00:00:00 2001 From: marvin Date: Fri, 12 Jul 2024 10:39:09 +0800 Subject: [PATCH 2/2] perf db makeQueryBytes --- query_column_add.go | 3 +-- query_column_drop.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/query_column_add.go b/query_column_add.go index 7baca8a35..647c67370 100644 --- a/query_column_add.go +++ b/query_column_add.go @@ -118,8 +118,7 @@ func (q *AddColumnQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte //------------------------------------------------------------------------------ func (q *AddColumnQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Result, error) { - bytes := make([]byte, 0) - queryBytes, err := q.AppendQuery(q.db.fmter, bytes) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err } diff --git a/query_column_drop.go b/query_column_drop.go index c5de3d1ef..1fef56fa7 100644 --- a/query_column_drop.go +++ b/query_column_drop.go @@ -114,8 +114,7 @@ func (q *DropColumnQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byt //------------------------------------------------------------------------------ func (q *DropColumnQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Result, error) { - bytes := make([]byte, 0) - queryBytes, err := q.AppendQuery(q.db.fmter, bytes) + queryBytes, err := q.AppendQuery(q.db.fmter, make([]byte, 0)) if err != nil { return nil, err }