惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Martin Fowler
Martin Fowler
GbyAI
GbyAI
P
Palo Alto Networks Blog
N
Netflix TechBlog - Medium
C
Cisco Blogs
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
A
About on SuperTechFans
PCI Perspectives
PCI Perspectives
Scott Helme
Scott Helme
TaoSecurity Blog
TaoSecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
W
WeLiveSecurity
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
月光博客
月光博客
N
News | PayPal Newsroom
Microsoft Azure Blog
Microsoft Azure Blog
G
GRAHAM CLULEY
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
MongoDB | Blog
MongoDB | Blog
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Know Your Adversary
Know Your Adversary
博客园 - Franky
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
F
Full Disclosure
V
Vulnerabilities – Threatpost
V
Visual Studio Blog
Forbes - Security
Forbes - Security
Attack and Defense Labs
Attack and Defense Labs
MyScale Blog
MyScale Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Tor Project blog

MySQL

请教大家一个关于 mysql 服务崩溃的问题 - V2EX 数据库连接数超了如何解决 - V2EX count 的语句优化问题 - V2EX 连接 MySQL 很慢的问题 - V2EX MYSQL UPDATE 在很短的时间内更新相同的语句,就会有告警,导至事务失败,有没有人遇到这问题? MySQL 磁盘读取飙升,导致阿里云服务器卡死 - V2EX 求 Macos 下面 homebrew 安装 mysql 到指定目录的方法 使用 EXISTS 优化 IN 子查询 - V2EX 什么时候可以将 mysql 默认隔离机制改为读已提交 跨平台的 MySQL Parser - V2EX MySQL 大表排序有什么好的方案?只能上 Mongo? Mysql 无法修改自增主键的 AUTO_INCREMENT 值 升级服务器后, mysql 性能反而更慢了,求排查思路 《高性能 MySQL》第三版:是否已经过时? 坑爹的字符集问题:踩到了 MySQL 的 bug 两个人的数据开发团队,被要求从零开始治理企业数据 MySQL 8.4 LTS 与 Metabase 奇怪兼容性问题:降级到 8.0.4 后问题解决 (1Panel and BT Panel 复现) - V2EX 公司内网,怎么搭建主备 mysql,高可用。故障自动切。 不买云服务 mysql 自增 ID 突然变为 int 最大值问题 覆盖还原 data 文件夹后, mysql 无法启动了 - V2EX 生产力工具 - V2EX 各位大佬,有个奇葩的技术问题 - V2EX 关于 mysql trx_id 的疑惑 发帖一问 sql 性能讨论 - V2EX 数据库高频更新问题 谁遇到过没 有啥好的解决方案部 - V2EX 有用过 SyncNavigator 或者类似的简单数据库同步软件吗, - V2EX 有什么优雅的 mysql 增加字段名的方法呢? - V2EX 各位 Mysql 大佬,问一个 8.0 版本 json 的问题 - V2EX mysql online DDL 时间很长,咋整,数据量不多,就 30W - V2EX 数据库中 select for update 和 version 乐观锁各自的适用场景是啥? - V2EX mysql 宿主机没有办法访问的问题 - V2EX mysql 求助 - V2EX MySQL 8.4 MGR 可以上生产吗? - V2EX mysql 亿级数据,数据筛选和导入导出 - V2EX 大佬们你们 Mysql 的数据库名称怎么分割的? - V2EX mysql 数据增量同步 - V2EX 新项目准备启动, MYSQL 选择 8.4.2 这个版本,有没什么坑? - V2EX mysql 一年新增 800 多万条数据,如果是单表的话请问服务器能支撑吗?各位有什么好的办法吗? - V2EX 新手求个远程数据库稳妥的解决方案~或者实时备份数据库的方法 - V2EX 铁子们,求助 docker 中 MySQL 导入数据库速度问题 - V2EX 大家的 SQL 一般怎么管理? - V2EX 询问一个慢查询的问题 - V2EX 现在用 mysql 的多 还是 mariadb 的多 - V2EX 关于 MySQL 查询咨询 - V2EX 请教个问题,如何快速的删除 mysql 的数据 求助:Mysql 数据文件夹如何被新安装的 Mysql 读取 - V2EX mysql 有没有什么中间件能模拟 mongodb? - V2EX 请问 debian12 mysql5.7 可以通过添加 apt 源安装吗?
mysql 遇到最愚蠢的查询性能问题,求解决 - V2EX
godall · 2025-01-14 · via MySQL

mysql 8.0 Windows 版本。

有这么一个股市行情表:##

tb_quote (
 op_date  ,
 code  ,
 price  ,
 ratio  ,
 hsl  ,
   index unique idx_1 (op_date,code) ,
   index idx_2(code)
 )

每个交易日 6000 条,一年几百万条规模。

现在有一个简单需求:##

  1. 筛选某一天涨幅在( 3%,5%)区间的股票,且换手率在( 5%-10%)区间之间
  2. 查看后一天的股票涨跌情况。

实现语句很简单:

方案一: 第一条语句在 1 秒内返回结果:(20 条记录)

select code from tb_quote where op_date='yyyy-mm-dd' and ratio >3 and ratio <5 and hsl>5 and hsl <10 

嵌套第二条后:

 select a.* from tb_quote a join ( 
   select code from tb_quote b where op_date='yyyy-mm-d1' and ratio >3 and ratio <5 and hsl>5 and hsl <10 ) t
 on a.code=t.code and a.op_date='yyyy-mm-d2' 

执行时间就超过 1 分钟!

** 查看 mysql 解释: **

  1. simple b,key idx_1 ,key_len=3,ref=const ,rows=s5373,filterd 0.05, Extra:using where
  2. simple a, key idx_2, key_len=30, ref=tb_quote.code, rows=465 ,filtered 0.21, Extra:using where

** 方案二: ** 但是如果把第一条语句的结果保存在一个表 tmp 里面,并且 code 建立普通索引以后,变成:

select a.* from tb_quote a join (
 select code from tmp ) t
on a.code=t.codeand a.op_date='yyyy-mm-d3'

执行时间不超过 1 秒!!!

** 查看 mysql 解释:**

  1. simple a, key idx_1, key_len=3, ref=const, rows=5365 ,filtered 100, Extra:useing where
  2. simple tmp, key idx_code ,key_len=29,ref=a.f12 ,rows=1, filterd 100, Extra:using where

发现差别在:

  1. 次序不同,方案二子表 tmp 在前,方案一子表 b 在后;
  2. filtered 值不同,方案二是 100 ,方案一只有 0.05 ;

不知道 mysql 是怎么优化的?如果不用中间表过渡的话,应该怎么写 sql ?