Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ edition = "2024"
pgdog-plugin = { path = "./pgdog-plugin", version = "0.4.0", default-features = false }
pgdog-config = { path = "./pgdog-config", version = "0.1.0" }
pgdog-postgres-types = { path = "./pgdog-postgres-types"}
pg_raw_parse = { git = "https://github.com/pgdogdev/pg_raw_parse.git", rev = "86acb50" }
pg_raw_parse = { git = "https://github.com/pgdogdev/pg_raw_parse.git", rev = "c5b3b75" }
bon = "3.9"
schemars = { version = "1.2.1", features = ["uuid1"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion integration/dry_run/test/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("sequelize", async function () {
let found = false;
for (let i = 0; i < cache.rows.length; i++) {
let row = cache.rows[i];
if (row.query.startsWith('SELECT "id", "email", "createdAt"')) {
if (row.query.startsWith('SELECT id, email, "createdAt"')) {
assert(parseInt(row.direct) > 0);
found = true;
}
Expand Down
11 changes: 7 additions & 4 deletions pgdog/src/frontend/router/parser/cache/cache_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::collections::HashMap;
use std::time::Duration;

use parking_lot::Mutex;
use pg_raw_parse::{deparse, nodes};
use std::sync::Arc;
use tracing::debug;

Expand Down Expand Up @@ -212,19 +213,21 @@ impl Cache {
/// Used by dry run mode to keep stats on what queries are routed correctly,
/// and which are not.
///
pub fn record_normalized(&self, query: &str, route: &Route) -> Result<(), Error> {
let normalized = normalize(query)?;
pub fn record_normalized(&self, query: &nodes::RawStmt, route: &Route) -> Result<(), Error> {
let normalized = normalize(query);
let normalized = deparse(normalized.stmt())?;
let normalized = normalized.as_str();

{
let mut guard = self.inner.lock();
if let Some(entry) = guard.queries.get(normalized.as_str()) {
if let Some(entry) = guard.queries.get(normalized) {
entry.update_stats(route);
guard.stats.hits += 1;
return Ok(());
}
}

let entry = Ast::new_record(&normalized)?;
let entry = Ast::new_record(normalized)?;
entry.update_stats(route);

let mut guard = self.inner.lock();
Expand Down
6 changes: 4 additions & 2 deletions pgdog/src/frontend/router/parser/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,10 @@ impl QueryParser {
if context.dry_run {
// Record statement in cache with normalized parameters.
if !statement.cached {
let query = context.query()?.query();
Cache::get().record_normalized(query, command.route())?;
Cache::get().record_normalized(
statement.ast.into_iter().next().ok_or(Error::EmptyQuery)?,
command.route(),
)?;
}
Ok(command.dry_run())
} else {
Expand Down
Loading