Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary subquery in DeptMapper.list #63

Open
wtune opened this issue Jan 10, 2020 · 0 comments
Open

Unnecessary subquery in DeptMapper.list #63

wtune opened this issue Jan 10, 2020 · 0 comments

Comments

@wtune
Copy link

wtune commented Jan 10, 2020

The following query defined in DeptMapper.xml is not optimal:

    <select id="list" resultType="map">
        select
...
        from sys_dept where 1 = 1
...
        <if test="deptId != null and deptId != ''">
            and (dept_id = #{deptId} or dept_id in ( select dept_id from sys_dept where pids like CONCAT('%$[', #{deptId}, '$]%') escape '$' ))
        </if>
        order by sort ASC
    </select>

The sub-query could be eliminated and changes to a predicate on pids.

and (dept_id = #{deptId} or pids like CONCAT('%$[', #{deptId}, '$]%') escape '$')
wtune added a commit to wtune/Guns that referenced this issue Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant