有看到这样的写法,想要优化一下
<select id="selectProperty">
select distinct t.*
from table t
where t.property1 = #{porperty1}
and t.property2 = #{porperty2}
</select>
想去除select *,改为
<sql id="ALL_COLUMNS">
property1, property2, property3
</sql>
<select id="selectProperty">
select distinct <include refid="ALL_COLUMNS"/>
from table t
where t.property1 = #{porperty1}
and t.property2 = #{porperty2}
</select>
想请教修改后效果应该是和原来一致的吧,会不会有什么问题。
同时还有一个疑问,distinct * 理论上把所有字段都不同的记录才看做不同,其中主键id是增长的,这样子加distinct的意义在哪呢,id不同,那么理论上这样写distinct也没有查出重复记录从而去重的执行场景呢。
有主键还不如不加,加了还会变慢