mirror of
https://github.com/ent/ent.git
synced 2026-04-28 13:40:56 +03:00
dialect/sql/sqlgraph: avoid creating tx blocks for single DELETE statements
In PostgreSQL, every statement is executed within a transaction. Therefore, we can avoid creating transaction blocks manually (group of statements surrounded by BEGIN and COMMIT) for DeleteNodes operation as it's implemented with a single statement. Benchmark for 4000 operations was improved from: 14.54s 7270455 ns/op 3702 B/op 81 allocs/op To: 5.36s 2679935 ns/op 2864 B/op 59 allocs/op --- MySQL and SQLite share the same behavior. Please see https://github.com/ent/ent/pull/1858 for more info.
This commit is contained in:
committed by
Ariel Mashraki
parent
ee606f4e86
commit
b23a0e8554
@@ -1816,10 +1816,8 @@ func TestUpdateNodes(t *testing.T) {
|
||||
func TestDeleteNodes(t *testing.T) {
|
||||
db, mock, err := sqlmock.New()
|
||||
require.NoError(t, err)
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec(escape("DELETE FROM `users`")).
|
||||
WillReturnResult(sqlmock.NewResult(0, 2))
|
||||
mock.ExpectCommit()
|
||||
affected, err := DeleteNodes(context.Background(), sql.OpenDB("", db), &DeleteSpec{
|
||||
Node: &NodeSpec{
|
||||
Table: "users",
|
||||
@@ -1833,10 +1831,8 @@ func TestDeleteNodes(t *testing.T) {
|
||||
func TestDeleteNodesSchema(t *testing.T) {
|
||||
db, mock, err := sqlmock.New()
|
||||
require.NoError(t, err)
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec(escape("DELETE FROM `mydb`.`users`")).
|
||||
WillReturnResult(sqlmock.NewResult(0, 2))
|
||||
mock.ExpectCommit()
|
||||
affected, err := DeleteNodes(context.Background(), sql.OpenDB("", db), &DeleteSpec{
|
||||
Node: &NodeSpec{
|
||||
Table: "users",
|
||||
|
||||
Reference in New Issue
Block a user