今天改了 bug,看到了一个 sql,顿时惊了。。。。。 这个是新项目,还没上线这部分内容。。

2020-07-03 14:08:59 +08:00
 luxinfl
SELECT
a.*
FROM
(
SELECT
a.*
FROM
(
SELECT
a.*
FROM
(
SELECT
a.*
FROM
(
SELECT
a.*
FROM
(
SELECT
PLATFORM_REQUEST_CODE AS platformRequestCode,
AGGTEGATE_REQUEST_CODE AS aggtegateRequestCode,
CREATE_TIME AS createTime,
STATUS AS payStatus,
MERCHANT_GENERATE_CODE AS platformCode,
USER_CODE AS buyCode,
CHANNEL_NO AS channelNo
FROM
tb_aggtegate_payment_request
WHERE
STATUS != '00'
AND DEL_FLAG = 0
AND IS_VALID = 0
ORDER BY
CREATE_TIME DESC
) a
LEFT JOIN ( SELECT CHANNEL_REQUEST_CODE AS channelOrderCode, AGGTEGATE_REQUEST_CODE AS channelaggtegateRequestCode FROM tb_channel_send_report WHERE DEL_FLAG = 0 ) b ON a.aggtegateRequestCode = b.channelaggtegateRequestCode
) a
LEFT JOIN ( SELECT MERCHANT_INFO_CODE, MERCHANT_INFO_NAME AS platformName FROM tb_merchant_info WHERE DEL_FLAG = 0 ) c ON c.MERCHANT_INFO_CODE = a.platformCode
) a
LEFT JOIN ( SELECT PLATFORM_USER_CODE, MERCHANT_NAME AS merchantName FROM tb_user_info WHERE DEL_FLAG = 0 ) b ON a.buyCode = b.PLATFORM_USER_CODE
) a
LEFT JOIN ( SELECT CHANNEL_CODE, CHANNEL_NAME AS channelName FROM tb_channel_info WHERE DEL_FLAG = 0 ) b ON a.channelNo = b.CHANNEL_CODE
) a
LEFT JOIN ( SELECT AGGTEGATE_REQUEST_CODE, TIME_END AS payTime FROM tb_wxpay_order_business WHERE DEL_FLAG = 0 AND IS_VALID = 0 ) b ON a.aggtegateRequestCode = b.AGGTEGATE_REQUEST_CODE
WHERE
1 = 1
11492 次点击
所在节点    程序员
85 条回复
lovecy
2020-07-04 14:51:19 +08:00
```
啊哈哈哈哈,没有效果啊,白格式化了大半天,貌似 markdown 语法也无效
```
shakoon
2020-07-04 18:23:56 +08:00
说实话我没看懂这个拉屎人的目的,left join 一堆东西但最后都没有用到 join 得到的字段。

SELECT AA.PLATFORM_REQUEST_CODE AS PLATFORMREQUESTCODE,
AA.AGGTEGATE_REQUEST_CODE AS AGGTEGATEREQUESTCODE,
AA.CREATE_TIME AS CREATETIME,
AA.STATUS AS PAYSTATUS,
AA.MERCHANT_GENERATE_CODE AS PLATFORMCODE,
AA.USER_CODE AS BUYCODE,
AA.CHANNEL_NO AS CHANNELNO
FROM TB_AGGTEGATE_PAYMENT_REQUEST AA
LEFT JOIN TB_CHANNEL_SEND_REPORT BB
ON BB.DEL_FLAG = 0
AND AA.AGGTEGATE_REQUEST_CODE = BB.CHANNELAGGTEGATEREQUESTCODE
LEFT JOIN TB_MERCHANT_INFO CC
ON CC.DEL_FLAG = 0
AND CC.MERCHANT_INFO_CODE = AA.MERCHANT_GENERATE_CODE
LEFT JOIN TB_USER_INFO DD
ON DD.DEL_FLAG = 0
AND AA.USER_CODE = DD.PLATFORM_USER_CODE
LEFT JOIN TB_CHANNEL_INFO EE
ON EE.DEL_FLAG = 0
AND AA.CHANNEL_NO = EE.CHANNEL_CODE
LEFT JOIN TB_WXPAY_ORDER_BUSINESS FF
ON FF.DEL_FLAG = 0
AND FF.IS_VALID = 0
AND AA.AGGTEGATE_REQUEST_CODE = FF.AGGTEGATE_REQUEST_CODE
WHERE AA.STATUS != '00'
AND AA.DEL_FLAG = 0
AND AA.IS_VALID = 0
ORDER BY AA.CREATE_TIME DESC
shakoon
2020-07-04 18:33:17 +08:00
@xxlee #32 @xxlee #37 没错,我整理了一下,发现这坨屎的核心也就中间那十行
@luxinfl #42 查不查到 name 有什么关系呢,最后的结果集并没有 name,所有的 join 都没有用处,反而可能会导致结果集数量上有增加,里面若干重复的数据
realpg
2020-07-05 00:35:13 +08:00
以前在一个公司招聘 PHP,有一个 JAVA 开发商业软件转过来的大佬。

面试题有一个数据库结构跟所要的查询结果格式比较蹩脚的题,基本考察就是性能考虑,这么进行交叉,循环设计

这个大佬拿笔记本摆弄了半天,非常牛逼的特意给我炫耀他接这题的方式,一条 2KB 的 SQL 语句拼接……

那还是跑在笔记本的测试库下本身也就几十万数据量下,一个查询卡了能有 0.5 秒……
pydiff
2020-07-05 11:27:49 +08:00
是我的话我直接扔回给写的人,看着就觉得恶心

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/686858

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX