【发布时间】:2021-05-14 19:35:42
【问题描述】:
在具有大约 1M 条记录的表上运行的相当复杂的(取决于标准)查询。创建一些临时表并构建数组和jsonb。
在本地主机上,我平均得到 2.5 秒。 在 Google SQL 上,我得到 17-19 秒。
注意:
- 其他查询,如简单选择,在服务器上比在本地上要快。应该如此。
- 我确实运行了 Vacuum,重建了所有索引,检查了挂起过程。一切顺利。
- 我玩过资源。创建了一个具有 8 个 VCPU 和 16Gb 内存的实例。结果几乎相同。
- 我检查了 proc、mem、disc。没问题。
这是来自explain analyse最慢查询的结果。
这里是本地人
可能是什么?
可能与this 重复,但未得到答复,已使用 2 年且没有标签。我会试试运气的。
L.E.解释分析文本中的详细内容
Update on public.customers (cost=30.38..207.32 rows=127 width=104) (actual time=13105.151..13105.154 rows=0 loops=1)
Planning Time: 1.852 ms
Execution Time: 13105.306 ms
-> Hash Join (cost=30.38..207.32 rows=127 width=104) (actual time=316.371..13091.937 rows=42 loops=1)
" Output: customers.id, customers.company_id, customers.sap_id, customers.parent_sap_id, jsonb_set(customers.stats, '{consolidatedSales}'::text[], jsonb_build_array(calculateconsolidatedstats(customers.id, customers.sap_id, ((date_part('year'::text, (CURRENT_DATE)::timestamp without time zone) - '2'::double precision))::integer), calculateconsolidatedstats(customers.id, customers.sap_id, ((date_part('year'::text, (CURRENT_DATE)::timestamp without time zone) - '1'::double precision))::integer), calculateconsolidatedstats(customers.id, customers.sap_id, (date_part('year'::text, (CURRENT_DATE)::timestamp without time zone))::integer)), true), customers.tags, customers.account_manager_id, customers.created_by_id, customers.customer_status_id, customers.created_at, customers.updated_at, customers.ctid, parents_with_sales.ctid"
Inner Unique: true
Hash Cond: (customers.id = parents_with_sales.id)
-> Seq Scan on public.customers (cost=0.00..74.54 rows=254 width=924) (actual time=0.021..0.419 rows=254 loops=1)
-> Hash (cost=27.88..27.88 rows=200 width=10) (actual time=0.086..0.088 rows=42 loops=1)
" Output: parents_with_sales.ctid, parents_with_sales.id"
" Output: customers.id, customers.company_id, customers.sap_id, customers.parent_sap_id, customers.stats, customers.tags, customers.account_manager_id, customers.created_by_id, customers.customer_status_id, customers.created_at, customers.updated_at, customers.ctid"
Buckets: 1024 Batches: 1 Memory Usage: 10kB
-> HashAggregate (cost=25.88..27.88 rows=200 width=10) (actual time=0.059..0.072 rows=42 loops=1)
" Output: parents_with_sales.ctid, parents_with_sales.id"
Group Key: parents_with_sales.id
Batches: 1 Memory Usage: 40kB
-> Seq Scan on pg_temp_7.parents_with_sales (cost=0.00..22.70 rows=1270 width=10) (actual time=0.010..0.019 rows=42 loops=1)
" Output: parents_with_sales.ctid, parents_with_sales.id"
【问题讨论】:
-
1)
explain (analyse, verbose, buffers, settings) ...了解更多详情; 2) 请输入文本。 -
@marian.vladoi:这将如何与 PostgreSQL 一起使用?
-
@Abelisto - 完成。见 L.E.
-
@marian.vladoi - 完成。不知道它有什么帮助,但我添加了它。
标签: sql postgresql performance google-cloud-sql