postgresql一次线上通过执行计划解决sql查询慢问题分享

本文分享了一次通过分析和调整PostgreSQL执行计划,成功解决SQL查询耗时过长的问题。通过建立索引和理解执行顺序,显著减少了查询时间。文章详细解析了各个执行步骤,包括Bitmap Index Scan、Bitmap Heap Scan、Hash Join和Sort操作,强调了正确估算成本和调整work_mem参数的重要性。
摘要由CSDN通过智能技术生成
explain analyze 
select
				distinct
					tah.id ,
					tah.hcbt ,
					tah.hclx ,
					(
					select
						dict."name"
					from
						pro_admin.t_dict dict
					where
						dict.code = tah.hclx
						and dict.type_code = 'HCLX') hclxName,
					tah.hcnr ,
					tah.ajbh ,
					tah.fbdw ,
					(
					select
						td.short_name
					from
						pro_admin.t_department td
					where
						td.code = tah.fbdw ) fbdwName,
					tah.fbsj ,
					tah.gkcd ,
					(
					select
						dict."name"
					from
						pro_admin.t_dict dict
					where
						dict.code = tah.gkcd
						and dict.type_code = 'GKCD') gkcdName,
					taf.qszt ,
					(
					select
						dict."name"
					from
						pro_admin.t_dict dict
					where
						dict.code = taf.qszt
						and dict.type_code = 'QSZT') qsztName,
					taf.ly ,
					taf.sfzf ,
					(
					select
						dict."name"
					from
						pro_admin.t_dict dict
					where
						dict.code = taf.ly
						and dict.type_code = 'SFZF') sfzfName,
					coalesce(( select dict."name" from pro_admin.t_dict dict where dict.code = taf.ly and dict.type_code = 'AJXT-LY'), '无') lyName,
			(select name from pro_admin.t_dict where enable and type_code  = 'ZLJB' and code = tah.level::text) level_label,
			tah.level,
			(select description from pro_admin.t_dict where enable and type_code  = 'ZLJB' and code = tah.level::text) level_desc,
			tah.to_sign_time,
			tah.to_fk_time,
			tah.hcbh
				from
				combined_
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值