You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT
enumlabel
FROMpg_catalog.pg_enumWHERE
enumtypid = $1ORDER BY
enumsortorder
These type validation queries significantly impact performance, especially with high DB RTTs:
Single query: ~8ms
With type checks: ~24ms (3x slower)
This runtime type checking creates unnecessary overhead in production systems where types are stable and tracked in code. I understand that this is required in many cases and is a good base setup, but allowing for disabling this functionality would greatly improve performance in many cases.
Proposed Solution
Add a configuration option to disable type checking queries, implemented either:
At build time through the query_as! macro system
At runtime via Pool settings (similar to test_before_acquire), e.g., validate_types_before_execution: bool
Attempted Workarounds
query_as_unchecked!()
Direct query!() with manual struct construction
Neither approach resolved the performance issue.
asyncfnget_user_by_id<'a>(&self,tx:&mutBox<dynTransactionContext<'a>>,user_id:UserId,) -> RepositoryErrorResult<Option<UserRow>>{let user = sqlx::query_as!(UserRow,
r#" SELECT id as "id: UserId", name, family_name, email, email_verified, phone as "phone: SystemPhoneNumber", phone_verified, password_hash, locale, jurisdiction_code as "jurisdiction_code: SystemCountry", birthdate, gender as "gender: SystemGender", time_zone, blocked_until, excluded_until, created_at, updated_at, deleted_at FROM users WHERE id = $1 AND deleted_at IS NULL "#,
user_id.inner()).fetch_optional(&mut*tx.conn().await?).await?;Ok(user)}
The text was updated successfully, but these errors were encountered:
Problem Description
When executing queries with custom types (enums, etc.), SQLx performs two preliminary SQL queries before the actual query:
These type validation queries significantly impact performance, especially with high DB RTTs:
This runtime type checking creates unnecessary overhead in production systems where types are stable and tracked in code. I understand that this is required in many cases and is a good base setup, but allowing for disabling this functionality would greatly improve performance in many cases.
Proposed Solution
Add a configuration option to disable type checking queries, implemented either:
query_as!
macro systemtest_before_acquire
), e.g.,validate_types_before_execution: bool
Attempted Workarounds
query_as_unchecked!()
query!()
with manual struct constructionNeither approach resolved the performance issue.
Environment
Code Context
Type Definitions
Note
SystemPhoneNumber and SystemCountry are just wrapper types around Strings
Database Schema
Query Implementation
The text was updated successfully, but these errors were encountered: