Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# A view whose query has resjunk columns (here a sort key that isn't part of
# the output).  The whole-row Var used for ROW_MARK_COPY has the view's
# rowtype, i.e. excludes the resjunk columns, while the subquery scan's slot,
# described by the subquery's targetlist, includes them.  EPQ must be able to
# restore the whole-row datum into that slot.
 
setup
{
  CREATE TABLE epq_rj_lock (id int PRIMARY KEY, n int);
  INSERT INTO epq_rj_lock VALUES (1, 0);
  CREATE TABLE epq_rj_data (id int, t text);
  INSERT INTO epq_rj_data VALUES (1, 'x');
  CREATE VIEW epq_rj_view AS SELECT id FROM epq_rj_data ORDER BY t;
}
 
teardown
{
  DROP VIEW epq_rj_view;
  DROP TABLE epq_rj_data, epq_rj_lock;
}
 
session s1
setup { SET default_transaction_isolation = 'read committed'; }
step begin1 { BEGIN; }
step update1 { UPDATE epq_rj_lock SET n = n + 1 WHERE id = 1; }
step commit1 { COMMIT; }
 
session s2
setup { SET default_transaction_isolation = 'read committed'; }
step read2
{
  SELECT l.id, l.n
  FROM epq_rj_lock l JOIN epq_rj_view v ON v.id = l.id
  FOR UPDATE OF l;
}
step modify2
{
  UPDATE epq_rj_lock l SET n = n + 10
  FROM epq_rj_view v WHERE v.id = l.id
  RETURNING l.id, l.n;
}
step explain2
{
  EXPLAIN (COSTS OFF)
  SELECT l.id, l.n
  FROM epq_rj_lock l JOIN epq_rj_view v ON v.id = l.id
  FOR UPDATE OF l;
}
 
# Without a concurrent update, no EPQ reconstruction is needed.
permutation begin1 update1 commit1 read2
 
# EPQ reconstructs the view's row from its whole-row datum.  The view's ORDER
# BY keeps it from being pulled up.
permutation explain2 begin1 update1 read2 commit1
permutation begin1 update1 modify2 commit1