INSERT INTO contacts_lists (contact_id, list_id)
SELECT contact_id, 110689 AS list_id
FROM plain_contacts
WHERE TRUE
AND is_print = TRUE
AND ( ( TRUE
AND country_id IN (231,39)
AND company_type_id IN (2,8,12,5,6,4,3,9,10,13,11,1,7)
AND is_broadcast = TRUE )
OR ( TRUE
AND country_id IN (15,59,73,74,81,108,155,165,204,210,211,230)
AND company_type_id IN (2,8,12,5,6,4,3,9,10,13,11,1,7)
AND is_broadcast = TRUE )
OR ( TRUE
AND country_id IN (230)
AND company_type_id IN (2,8,12,5,6,4,3,9,10,13,11,1,7)
AND is_broadcast = TRUE ))
AND (NOT EXISTS (
SELECT title_id
FROM company_types_lists_titles
WHERE company_types_list_id = 92080)
OR title_id IN (
SELECT title_id
FROM company_types_lists_titles
WHERE company_types_list_id = 92080))
AND company_type_id = 2
AND country_id IN (
SELECT country_id
FROM countries_lists
WHERE list_id = 110689)
AND ((state_id IS NULL
OR country_id NOT IN (231,39)
OR state_id IN (
SELECT state_id
FROM lists_states
WHERE list_id = 110689))
OR zone_ids && ARRAY(
SELECT zone_id
FROM lists_zones
WHERE list_id = 110689)
)
AND (NOT EXISTS (
SELECT award_id
FROM company_types_lists_top_awards
WHERE company_types_list_id = 92080)
OR top_award_ids && ARRAY(
SELECT award_id
FROM company_types_lists_top_awards
WHERE company_types_list_id = 92080))
我使用了 postgresql,它从各种表中选择 30000 行,从各种表中选择数据需要不到一秒钟的时间。但是在选择需要越来越多时间插入另一个表的数据之后。如何减少插入时间。这是我的查询。在这个选择查询中给出了近 3000 万条记录。