DML query must be inside a transaction?
What I Did
- I created some insert queries, with and without using transaction. I'm using postgresqlworker
What I Expected
- Should have new records for both cases
What I Saw Instead
- Only insert query runs with transaction successful (which creates a new record)
- The normal query couldn't create a record but it returned no error
My question is: does DML query only work with transaction? The performance with and without transaction is really different:
With transaction:
goos: linux goarch: amd64 pkg: github.com/tinoquang/hera-client/internal/services/ledger cpu: AMD Ryzen 7 5800H with Radeon Graphics
BenchmarkHeraCreateWithTranasction 208 5696227 ns/op 3774 B/op 94 allocs/op BenchmarkHeraCreateWithTranasction-2 429 2706561 ns/op 3779 B/op 94 allocs/op BenchmarkHeraCreateWithTranasction-4 733 1551963 ns/op 3804 B/op 94 allocs/op
Without transaction:
goos: linux goarch: amd64 pkg: github.com/tinoquang/hera-client/internal/services/ledger cpu: AMD Ryzen 7 5800H with Radeon Graphics
BenchmarkHeraCreateWithTranasction 717 1644049 ns/op 3125 B/op 78 allocs/op BenchmarkHeraCreateWithTranasction-2 1580 756031 ns/op 3101 B/op 78 allocs/op BenchmarkHeraCreateWithTranasction-4 3846 315235 ns/op 3101 B/op 78 allocs/op
@tinoquang Thanks for taking time to test this out. I appreciate it! Would you be able to share a snippet of the code you tried? We'll review that and get back to you.