Skip to content

Feedback on Skip Describe portal when executing prepared statements #2460

@jackc

Description

@jackc

Currently, pgx always sends a Describe portal message when executing a prepared statement. It receives a RowDescription message in response. This is convenient as result sets always include a RowDescription first regardless of whether the query was executed with the simple protocol, the extended protocol without a prepared statement, or the extended protocol with a prepared statement.

But pgx always Describe prepared statements when it creates them. So it already has the RowDescription. The only thing it lacks is the format (text or binary) of the result fields as that is specified per execution. But if pgx remembered the formats it requested when it sent the query it could synthesize the complete RowDescription without needing to ask PostgreSQL to resend it.

There is a tiny improvement in runtime, on the order of a few 100ns to a 1000ns per query. Per query memory usage and allocations are reduced by a significant amount. Whether it is significant in the context of an application is another question.

It also reduces the amount of network traffic. In some benchmarks the amount of bytes received is reduced to less than half. The percentage change will vary significantly based on the number of columns in the result set, which determines the size of the RowDescription message, and the number of rows returned. If only one row is returned it is quite likely that RowDescription is bigger than the actual data. But if many rows are returned then the RowDescription cost is insignificant.

#2422 implements this change. There should be no application visible behavior changes, just better performance. However, it does restructure a lot of internal code. So I am requesting additional testing before this is merged.

Please test the PR on your applications and add a 👍 if it works. If you have problems or have questions please respond here.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions