V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  jov1  ›  全部回复第 1 页 / 共 1 页
回复总数  9
25 天前
回复了 Vesc 创建的主题 数据库 求 SQL 优化建议
@Vesc 如果打算程序先查 B ,然后再查 A ,这个没关系,比如原来可能是这样
select
a.row1 ,a. row2
from a
join b on b.order_id = a.order_id
<where>
a.age > 18
<if test="name != null and namelength()>0">
and (a.name = 'xx' or b.name = 'xx')
</if>
</where>


那你程序就是先单独查 b 的,比如 name 是需要 ab 表都查的,,再将这个 orderIds 作为条件二次查询 a
如果 name 不为空的情况下,就先查 b ,然后返回 order_id(看你描述,ab 是通过 order_id 关联的)
select order_id
from b
where .name = 'xx'

然后
select
a.row1 ,a. row2
from a
<where>
a.age > 18
<if test="name != null and namelength()>0">
and (a.name = 'xx' or a.order_id in
<if test="orderIds != null and orderIds.size() > 0">
<foreach collection="orderIds" item="orderId" separator="," open="(" close=")">
#{orderId,jdbcType=BIGINT}
</foreach>
</if>
)
</if>

</where>
25 天前
回复了 Vesc 创建的主题 数据库 求 SQL 优化建议
@Vesc 如果打算程序先查 B ,然后再查 A ,这个没关系,比如原来可能是这样
select
a.row1 ,a. row2
from a
join b on b.order_id = a.order_id
<where>
<if test="name != null and namelength()>0">

</where>
where
那你程序无非就是先一天 sql 查询
25 天前
回复了 Vesc 创建的主题 数据库 求 SQL 优化建议
这个要看具体情况,比如你查出来的列表不需要 b ,只需要 a 的字段,可以考虑下面这两种,结合执行计划看下索引命中情况。如果 ab 联表查询慢,但是单独查 b 的情况不慢,也可以程序中先单独根据条件查符合 b 的 order_id 再执行 a 的查询

select distinct a.xx, a.xx,a.xx
from a
join b on a.order_id = b.order_id
where
a.xx = ?
and b.xx=?
或者
select a.xx, a.xx,a.xx
from a
where a.order_id in (
select order_id from b where order_id is not null
and xxx=? and xxx=?
)
51 天前
回复了 atfeel 创建的主题 程序员 大佬都在什么验证码方案?
如果用的云厂商的短信发送,我这个目前用的腾讯云,配套有相应的安全策略配置之类的,比如配置发送频率,ip 限制等,同时也提供验证码服务,就是你描述的拖动类验证码,不过要收费不是免费的,这种拦截的事情交给他们来
79 天前
回复了 guch99999 创建的主题 Java 求教 springcloud 集成 websocket 报错 1009.
WebSocket 缓冲区小,传入数据太大,试试找的例子,构建 websocket 客户端连接的时候,配置下大小

WebSocketContainer container = new WsWebSocketContainer();
// 设置二进制消息缓冲区大小(以字节为单位)
container.setDefaultMaxBinaryMessageBufferSize(5120000);
// 设置文本消息缓冲区大小(以字节为单位)
container.setDefaultMaxTextMessageBufferSize(5120000);
// 设置会话空闲超时时间(以毫秒为单位)
container.setDefaultMaxSessionIdleTimeout(15 * 60000L);
StandardWebSocketClient client = new StandardWebSocketClient(container);
144 天前
回复了 jov1 创建的主题 程序员 请教一个数据库或代码的唯一性设计问题
@Rickkkkkkk
@xhawk
@fuyufjh 嗯,感觉大家提供意见和参考,之前也问了 gpt ,给出的方案是类似 path 级别这样的,但是测试几个场景后还是会存在我说的那种错误判断包含的情况,试着在这基础上不断调整,感觉可以满足,这样写可以避免这种情况(1,2,2),传入(1,2,23)
select CONCAT_WS(',',ifnull(a,''), ifnull(b,''), ifnull(c,'')) as uniqueKey
from t
where t.uniqueKey = #{uniqueKey,jdbcType=VARCHAR}
or t.uniqueKey like CONCAT(#{uniqueKey,jdbcType=VARCHAR}, ',%')
or #{uniqueKey,jdbcType=VARCHAR} like CONCAT(t.uniqueKey, ',%')
if (BooleanUtils.isTrue(xx.getEnableVoice()) {
// 校验 voiceContent 是否为空
} else {
xx.setVoiceContent(null);
} 应该也可以实现 ConstraintValidator 来自定义校验规则,拓展注解之类的,只是目前是类似这样处理的
也会有类似问题,通用的用提供的注解声明,这种情况判定来动态处理验证的,我目前放在业务实现里面校验处理,因为可能还需要对数据处理,比如 enableVoice 不等于 true ,如果前端传入了 voiceContent ,后端其实还类似需要清空这个值,那么顺手可以把校验 enableVoice=true 时 voiceContent 的非空校验做了,
类似于
if (BooleanUtils.isTrue(xx.getEnableVoice()) {

}
支持一下,希望能体验用上
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5138 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 25ms · UTC 08:27 · PVG 16:27 · LAX 01:27 · JFK 04:27
Developed with CodeLauncher
♥ Do have faith in what you're doing.