-
Notifications
You must be signed in to change notification settings - Fork 242
/
psql-query.patch
41 lines (37 loc) · 1.93 KB
/
psql-query.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
diff --git a/benchmarks/targets/postgres.rs b/benchmarks/targets/postgres.rs
index bb63c4e..91b583a 100644
--- a/benchmarks/targets/postgres.rs
+++ b/benchmarks/targets/postgres.rs
@@ -41,7 +41,7 @@ pub fn make(dbn: &str, getters: usize) -> Box<Backend> {
let conn = pool.get().unwrap();
// create tables
- conn.execute("CREATE TABLE art (id bigint, title varchar(255), votes bigint)",
+ conn.execute("CREATE TABLE art (id bigint, title varchar(255))",
&[])
.unwrap();
conn.execute("CREATE TABLE vt (u bigint, id bigint)", &[]).unwrap();
@@ -65,7 +65,7 @@ impl Backend for r2d2::Pool<PCM> {
impl Putter for PC {
fn article<'a>(&'a mut self) -> Box<FnMut(i64, String) + 'a> {
- let prep = self.prepare("INSERT INTO art (id, title, votes) VALUES ($1, $2, 0)").unwrap();
+ let prep = self.prepare("INSERT INTO art (id, title) VALUES ($1, $2)").unwrap();
Box::new(move |id, title| {
prep.execute(&[&id, &title]).unwrap();
})
@@ -73,17 +73,15 @@ impl Putter for PC {
fn vote<'a>(&'a mut self) -> Box<FnMut(i64, i64) + 'a> {
let pv = self.prepare("INSERT INTO vt (u, id) VALUES ($1, $2)").unwrap();
- let pa = self.prepare("UPDATE art SET votes = votes + 1 WHERE id = $1").unwrap();
Box::new(move |user, id| {
pv.execute(&[&user, &id]).unwrap();
- pa.execute(&[&id]).unwrap();
})
}
}
impl Getter for PC {
fn get<'a>(&'a self) -> Box<FnMut(i64) -> Option<(i64, String, i64)> + 'a> {
- let prep = self.prepare("SELECT id, title, votes FROM art WHERE id = $1").unwrap();
+ let prep = self.prepare("SELECT art.id, art.title, COUNT(vt.u) FROM art LEFT JOIN vt USING (id) WHERE art.id = $1 GROUP BY art.id, art.title").unwrap();
Box::new(move |id| {
for row in prep.query(&[&id]).unwrap().iter() {
return Some((row.get(0), row.get(1), row.get(2)));