Skip to content

Commit

Permalink
Faster query with a simpler plan by joining with the CTE instead of m…
Browse files Browse the repository at this point in the history
…aking IN query (#113)

* Faster query with a simpler plan by joining with the CTE instead of making IN query

* Update cargo version
  • Loading branch information
ddorian committed Sep 13, 2023
1 parent 0ffb034 commit 7ce03aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmq-core"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
authors = ["Tembo.io"]
description = "Core functionality shared between the PGMQ Rust SDK and Postgres Extension"
Expand Down
5 changes: 3 additions & 2 deletions core/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,12 @@ pub fn read(name: &str, vt: i32, limit: i32) -> Result<String, PgmqError> {
LIMIT {limit}
FOR UPDATE SKIP LOCKED
)
UPDATE {PGMQ_SCHEMA}.{TABLE_PREFIX}_{name}
UPDATE {PGMQ_SCHEMA}.{TABLE_PREFIX}_{name} t
SET
vt = clock_timestamp() + interval '{vt} seconds',
read_ct = read_ct + 1
WHERE msg_id in (select msg_id from cte)
FROM cte
WHERE t.msg_id=cte.msg_id
RETURNING *;
"
))
Expand Down

0 comments on commit 7ce03aa

Please sign in to comment.