У меня проблема с медленным запросом при соединении двух секционированных таблиц. Этот запрос используется для проверки скорости:
EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON)
SELECT COUNT(*) AS erc_full_count
FROM event_record AS erc
LEFT OUTER JOIN ( SELECT id, event_record_id FROM rlc_data AS rld
WHERE rld.active is true and rld.deleted is FALSE
AND (NULL::BOOLEAN is NULL OR rld.group_event=NULL::BOOLEAN)
AND (NULL::TIMESTAMP IS NULL OR rld.created_time >= NULL::TIMESTAMP)
AND (NULL::TIMESTAMP IS NULL OR rld.created_time <= NULL::TIMESTAMP)
) AS sub_rld
ON erc.id = sub_rld.event_record_id
WHERE erc.deleted is FALSE
AND (-1::BIGINT = -1 OR erc.device_id=-1::BIGINT)
AND (-1::BIGINT = -1 OR erc.module_serial_number=-1::BIGINT)
AND (NULL::TIMESTAMP IS NULL OR erc.record_time >= NULL::TIMESTAMP)
AND (NULL::TIMESTAMP IS NULL OR erc.record_time <= NULL::TIMESTAMP)
AND erc.active is TRUE;
The main issue is with NESTED LOOP because it lasts more than 40 seconds.
This is a response that I got from database:
https://pastebin.com/VQpnTLYS