Skip to content

Commit 7643d28

Browse files
authored
[Improvement][api-sql] Optimize the sql for paging query project (#13172)
* Optimizing sql * add version join condition Co-authored-by: chenjiaming <chenjiaming@kezaihui.com>
1 parent 66e2027 commit 7643d28

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

  • dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper

dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,18 @@
8484
select
8585
<include refid="baseSqlV2">
8686
<property name="alias" value="p"/>
87-
</include>
88-
,
87+
</include> ,
8988
u.user_name as user_name,
90-
(SELECT COUNT(*) FROM t_ds_process_definition AS def WHERE def.project_code = p.code) AS def_count,
91-
(SELECT COUNT(*) FROM t_ds_process_definition_log def, t_ds_process_instance inst WHERE def.code =
92-
inst.process_definition_code and def.version = inst.process_definition_version AND def.project_code = p.code
93-
AND inst.state=1 ) as inst_running_count
89+
count(distinct def.id) AS def_count,
90+
count(distinct inst.id) as inst_running_count
9491
from t_ds_project p
9592
left join t_ds_user u on u.id=p.user_id
93+
left join t_ds_process_definition def
94+
on def.project_code = p.code
95+
left join t_ds_process_instance inst
96+
on inst.process_definition_code = def.code
97+
and inst.process_definition_version = def.version
98+
and inst.state = 1
9699
where 1=1
97100
<if test="projectsIds != null and projectsIds.size() > 0">
98101
and p.id in
@@ -105,7 +108,8 @@
105108
OR p.description LIKE concat('%', #{searchName}, '%')
106109
)
107110
</if>
108-
order by p.create_time desc
111+
group by p.id
112+
order by p.id desc
109113
</select>
110114
<select id="queryAuthedProjectListByUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project">
111115
select

0 commit comments

Comments
 (0)