Confusing results with lateral references

Поиск
Список
Период
Сортировка
От Ashutosh Bapat
Тема Confusing results with lateral references
Дата
Msg-id CAFjFpRdexAuu6aX=PtY-K-nT2RjmjFJ0PjGQHJOZXzWbABWLnA@mail.gmail.com
обсуждение исходный текст
Ответы Re: Confusing results with lateral references  (Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>)
Re: Confusing results with lateral references  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hi,

I am seeing different results with two queries which AFAIU have same semantics and hence are expected to give same results.

postgres=# \d t1
      Table "public.t1"
 Column |  Type   | Modifiers
--------+---------+-----------
 val    | integer |
 val2   | integer |

postgres=# \d t2
      Table "public.t2"
 Column |  Type   | Modifiers
--------+---------+-----------
 val    | integer |
 val2   | integer |

There's no data in the table to start with.

postgres=# insert into t1 values (1, 1);
postgres=# insert into t2 values (1, 1), (2, 2);

Session 1
postgres=# begin;
BEGIN
postgres=# update t1 set val = 2 where val2 = 1;
UPDATE 1

Session 2
postgres=# select * from t1, (select distinct val, val2 from t2) t2 where t1.val = t2.val for update of t1;

query waits here because of FOR UPDATE clause

Session 1
postgres=# commit;
COMMIT

Session 2 gives no rows
postgres=# select * from t1, (select distinct val, val2 from t2) t2 where t1.val = t2.val for update of t1;
val | val2 | val | val2
-----+------+-----+------
(0 rows)


Reset values of t1
postgres=# update t1 set val = 1 where val2 = 1;
UPDATE 1

Session 1
postgres=# begin;
BEGIN
postgres=# update t1 set val = 2 where val2 = 1;
UPDATE 1

Session 2
postgres=# select * from t1, lateral (select distinct val, val2 from t2 where t2.val = t1.val) t2 for update of t1;

query waits here

Session 1
postgres=# commit;
COMMIT

Session 2 gives results of the query
postgres=# select * from t1, lateral (select distinct val, val2 from t2 where t2.val = t1.val) t2 for update of t1;
 val | val2 | val | val2
-----+------+-----+------
   2 |    1 |   1 |    1
(1 row)

AFAIU, both the queries

select * from t1, (select distinct val, val2 from t2) t2 where t1.val = t2.val for update of t1;

AND

select * from t1, lateral (select distinct val, val2 from t2 where t2.val = t1.val) t2 for update of t1;

have same semantic and should give same results.

Is seeing different results expected behaviour?
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Kyotaro HORIGUCHI
Дата:
Сообщение: Re: [PROPOSAL] VACUUM Progress Checker.
Следующее
От: "Daniel Verite"
Дата:
Сообщение: Re: psql: add \pset true/false