AM
Size: a a a
AM
R
OB
R
OB
YS
OB
YS
АА
EZ
OB
D
B
VU
WITH keys AS (
SELECT hstore( %2%::TEXT[], array_fill(1::text, array[0]) ) natkey
)
SELECT thrd_lvl_documents.id, concat(
UPPER(COALESCE(thrd_lvl_documents.data::json#>'{employee}'->>'SecondName', '')) ||
UPPER(COALESCE(thrd_lvl_documents.data::json#>'{employee}'->>'Name', ''))
)AS nat_key
FROM
thrd_lvl_documents
JOIN snd_lvl_documents ON thrd_lvl_documents.snd_lvl_doc = snd_lvl_documents.id
JOIN fst_lvl_documents ON snd_lvl_documents.fst_lvl_doc = fst_lvl_documents.id
JOIN keys ON keys.natkey->concat(
UPPER(COALESCE(thrd_lvl_documents.data::json#>'{employee}'->>'SecondName', '')) ||
UPPER(COALESCE(thrd_lvl_documents.data::json#>'{employee}'->>'Name', ''))
) IS NOT NULL
WHERE
fst_lvl_documents.id = %1%::bigint
YS
EZ
VY
WITH keys AS (
SELECT hstore( %2%::TEXT[], array_fill(1::text, array[0]) ) natkey
)
SELECT thrd_lvl_documents.id, concat(
UPPER(COALESCE(thrd_lvl_documents.data::json#>'{employee}'->>'SecondName', '')) ||
UPPER(COALESCE(thrd_lvl_documents.data::json#>'{employee}'->>'Name', ''))
)AS nat_key
FROM
thrd_lvl_documents
JOIN snd_lvl_documents ON thrd_lvl_documents.snd_lvl_doc = snd_lvl_documents.id
JOIN fst_lvl_documents ON snd_lvl_documents.fst_lvl_doc = fst_lvl_documents.id
JOIN keys ON keys.natkey->concat(
UPPER(COALESCE(thrd_lvl_documents.data::json#>'{employee}'->>'SecondName', '')) ||
UPPER(COALESCE(thrd_lvl_documents.data::json#>'{employee}'->>'Name', ''))
) IS NOT NULL
WHERE
fst_lvl_documents.id = %1%::bigint
SELECT
JOIN keys ON keys.natkey->concat
(…`EXPLAIN (analyze, buffers)
чтобы видеть как тормозитYS
VU
SELECT
JOIN keys ON keys.natkey->concat
(…`EXPLAIN (analyze, buffers)
чтобы видеть как тормозитSelectдобавил.
JOIN keys ON keys.natkey->concat
фактически, оригинальный перл автора данного запроса (на входе массив натуральных ключей кастится к hstore, а тут мы, получая очередную запись thrd_lvl_documents на месте выдёргиваем из данных куски, соединяем их воедино и проверяем оператором "->" наличие этих данных в hstore). Explain с замазанными названиями таблиц и полей вам что-нибудь даст?VY
Selectдобавил.
JOIN keys ON keys.natkey->concat
фактически, оригинальный перл автора данного запроса (на входе массив натуральных ключей кастится к hstore, а тут мы, получая очередную запись thrd_lvl_documents на месте выдёргиваем из данных куски, соединяем их воедино и проверяем оператором "->" наличие этих данных в hstore). Explain с замазанными названиями таблиц и полей вам что-нибудь даст?