Skip to content

Concurrency insert in one transaction  #1137

@wisecsj

Description

@wisecsj

Issue description

  1. I know concurrency query in one transaction is not allowed,it will report error "busy buffer".But i want to confirm that is concurrency exec in one transaction is correct or allowed? I have done some tests and concurrency exec works fine

  2. According to database/sql doc,
    image
    But when i do concurrency query in one Stmt,the same error occurs:"busy buffer".

So,what's the correct way to use Stmt ...

Example code

	tx, err := db.Begin()
	if err != nil {
		t.Fatal(err)
	}
	defer tx.Rollback()
	stmt, err := tx.Prepare("select id from lnmp where id in (?,?,?,?,?,?,?)")
	if err != nil {
		t.Fatal(err)
	}
	defer stmt.Close()
	var wg sync.WaitGroup
	for i := 1; i < 10; i++ {
		i := i
		wg.Add(1)
		go func() {
			defer wg.Done()
			rows, err := stmt.Query(i, i+1, i+2, i+3,i+4,i+5,i+6)
			if err != nil {
				t.Logf("stmt query error:%v", err)
				return
			}
			defer rows.Close()
			for rows.Next() {
				var id int
				rows.Scan(&id)
			}
		}()
	}
	wg.Wait()

image

Configuration

Driver version (or git SHA):
1.4.0
Go version: run go version in your console
1.13
Server version: E.g. MySQL 5.6, MariaDB 10.0.20
MySQL 5.7
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
mac os 10.15.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions