Skip to content

Executing parallel queries with different connections in QueryMode.extended throws error #428

Description

@johannes-honeder

I tried using QueryMode.extended with named parameters instead of QueryMode.simple but when changing my code, I run into parallelization issues somewhere along the parse/bind/execute steps in Postgres.

In my code, I have implemented something like this:

Future executeQuery(String query, {Map<String, String>? parameters) async {
    # 1. get new connection from the pool
    var dbConn = await getConnection();
    
    # 2. execute the query
    if (parameters == null) {
        return dbConn.connection.execute(query);
    } else {
        return dbConn.connection.execute(Sql.named(query), parameters: parameters);
    }
}

I make sure that for each call of executeQuery, a new connection is assigned from a Connection Pool. However, if I run parallel queries with different parameter settings

result.addAll([
    executeQuery(query1, parameters1),         # parameterized query
    executeQuery(query2),                                # no parameters
]);

, I run into errors like:

  • "08P01: bind message supplies 1 parameters, but prepared statement "s/0" requires 0"
  • "42P05: prepared statement "s/1" already exist"
  • "42P05: prepared statement "s/2" does not exist"
    ...

I am guessing that the parse, bind and execute steps of the parallel queries are mixed up internally somehow. Is this a known behavior? To me this would make sense if using the same connection, but I explicitly make sure that when running parallel queries, each query is assigned a unique connection.

I appreciate any help or insights into this issue!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions