当前位置:网站首页>mysql在查询字符串类型的时候带单引号和不带的区别和原因
mysql在查询字符串类型的时候带单引号和不带的区别和原因
2022-07-29 05:21:00 【麻辣隔壁4】
最近在工作中处理数据,碰到的问题。
就是在查询股票历史数据的时候查询一只股票的日交易数据,由于在跑线程的时候没注意python写sql的时候没有带单引号。如下图所示:

然后就丢的服务器上定时跑任务,结果第二天早上发现数据没出来。然后悲剧了。就查找原因。一般数据量小了看不出来他们的差别。下面是这个表的数据量:

我先是把代码加上时间打印出来,分时间打印。跑出来的日志如下。

从图中可以看出查询数据占用了大量的时间,而计算几乎没用时间。于是我就把select语句复制到navicat中运行,下面是没带单引号的运行作用的时间:

然后我又将股票代码带上单引号进行运行。下面是截图

由俩副图可以看出,俩者运行查询速度相差10多秒。这是建立在900W数据的基础上测出来的。所以在进行字符串条件查询的时候一定要注意带上单引号。
不带单引号mysql会给你将数据库中的数据进行类型转换。这样就比较耗时间了。官方说明文档看下图:

敲黑板:1、在条件查询的时候按照字符类型进行查询,不要横跨太平洋进行跨字符类型查询。
2、对于数据量比较多的表尽量分表,建索引。
边栏推荐
- Super simple integration of HMS ml kit to realize parent control
- PHP write a diaper to buy the lowest price in the whole network
- “山东大学移动互联网开发技术教学网站建设”项目实训日志五
- 初探fastJson的AutoType
- Fantom (FTM) surged 45% before the FOMC meeting
- Some opportunities for young people in rural brand building
- 并发编程学习笔记 之 工具类CountDownLatch、CyclicBarrier详解
- XDFS&中国日报社在线协同编辑平台典型案例
- Get the number of daffodils
- From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
猜你喜欢

Power BI Report Server 自定义身份验证

MySQL decompressed version windows installation

突破硬件瓶颈(一):Intel体系架构的发展与瓶颈挖掘

iSCSI vs iSER vs NVMe-TCP vs NVMe-RDMA
![30 knowledge points that must be mastered in quantitative development [what is individual data]?](/img/13/9e5e44b371d79136e30dd86927ff3a.png)
30 knowledge points that must be mastered in quantitative development [what is individual data]?

Synchronous development with open source projects & codereview & pull request & Fork how to pull the original warehouse

C# 判断用户是手机访问还是电脑访问

Shanzhai coin Shib has a US $548.6 million stake in eth whale's portfolio - traders should be on guard

与张小姐的春夏秋冬(2)

Use of file upload (2) -- upload to Alibaba cloud OSS file server
随机推荐
Huawei 2020 school recruitment written test programming questions read this article is enough (Part 1)
“山东大学移动互联网开发技术教学网站建设”项目实训日志五
"Shandong University mobile Internet development technology teaching website construction" project training log I
The difference between link and @import importing external styles
How to PR an open source composer project
Some opportunities for young people in rural brand building
Power BI Report Server 自定义身份验证
如何在加密市场熊市中生存?
IDEA使用JDBC连接MySQL数据库个人详细教程
XDFS&中国日报社在线协同编辑平台典型案例
并发编程学习笔记 之 工具类CountDownLatch、CyclicBarrier详解
“山东大学移动互联网开发技术教学网站建设”项目实训日志六
Plato farm is expected to further expand its ecosystem through elephant swap
突破硬件瓶颈(一):Intel体系架构的发展与瓶颈挖掘
Read and understand move2earn project - move
30 knowledge points that must be mastered in quantitative development [what is individual data]?
Reporting Services- Web Service
DAO赛道异军突起,M-DAO的优势在哪里?
XDFS&空天院HPC集群典型案例
Get the number of daffodils