Skip to content
Merged
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
37 changes: 32 additions & 5 deletions tests/sqlx/src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1670,10 +1670,13 @@ SELECT $1::jsonb::{d} FROM generate_series(1, 5000)",
// Natural bare-operator form: `value {op} <lit>`. This
// is the inlinability tripwire — a broken inline flips
// it to Seq Scan.
let natural = format!(
"SELECT * FROM {table} WHERE value {op} '{lit}'::jsonb{cast}",
let natural_predicate = format!(
"value {op} '{lit}'::jsonb{cast}",
op = $op, cast = rhs_cast,
);
let natural = format!(
"SELECT * FROM {table} WHERE {natural_predicate}",
);
$crate::matrix::assert_index_scan_uses(
&mut *tx, &natural, index,
&format!(
Expand All @@ -1683,6 +1686,17 @@ SELECT $1::jsonb::{d} FROM generate_series(1, 5000)",
extractor = extractor, using = $using,
),
).await?;
let matched: i64 = sqlx::query_scalar(&format!(
"SELECT count(*) FROM {table} WHERE {natural_predicate}",
))
.fetch_one(&mut *tx)
.await?;
assert_eq!(
matched, 1,
"scale: natural-form `{op}` (rhs {cast:?}) must match exactly \
one row",
op = $op, cast = rhs_cast,
);

// Explicit extractor form: `{extractor}(value) {op}
// {extractor}(<lit>)`. Complements the natural form;
Expand All @@ -1700,11 +1714,13 @@ SELECT $1::jsonb::{d} FROM generate_series(1, 5000)",
// signature pins the domain), so skipping it here loses
// no coverage.
if !rhs_cast.is_empty() {
let extracted = format!(
"SELECT * FROM {table} \
WHERE {extractor}(value) {op} {extractor}('{lit}'::jsonb{cast})",
let extracted_predicate = format!(
"{extractor}(value) {op} {extractor}('{lit}'::jsonb{cast})",
extractor = extractor, op = $op, cast = rhs_cast,
);
let extracted = format!(
"SELECT * FROM {table} WHERE {extracted_predicate}",
);
$crate::matrix::assert_index_scan_uses(
&mut *tx, &extracted, index,
&format!(
Expand All @@ -1714,6 +1730,17 @@ WHERE {extractor}(value) {op} {extractor}('{lit}'::jsonb{cast})",
extractor = extractor, using = $using,
),
).await?;
let matched: i64 = sqlx::query_scalar(&format!(
"SELECT count(*) FROM {table} WHERE {extracted_predicate}",
))
.fetch_one(&mut *tx)
.await?;
assert_eq!(
matched, 1,
"scale: extractor-form `{op}` (rhs {cast:?}) must match \
exactly one row",
op = $op, cast = rhs_cast,
);
}
}
}
Expand Down
Loading