本篇文章为大家展示了SQL order by ID desc/asc加一个排序的字段解决查询慢问题的示例分析,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。解决方法就是在order by ID desc再加一个排序的字段,这样子可能会把速度提高很多。再加止排序的字段因查询而异了 如表代码如下:CREATE TABLE [dbo].[CMPP_SendCentre] ( [id] [int] IDENTITY (1, 1) NOT NULL , [SendType] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL , [SendDate] [datetime] NOT NULL , [Por免费主机域名t] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL , [Service_ID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL , [FeeType] [varchar] (2) COLLATE Chinese_PRC_CI_AS NOT NULL , [FeeCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NOT NULL , [Msg_Content] [varchar] (1024) COLLATE Chinese_PRC_CI_AS NOT NULL , [SendCount] [int] NOT NULL , [SucceedCount] [int] NOT NULL ) ON [PRIMARY] GO CREATE TABLE [dbo].[CMPP_SendCentreMo] ( [id] [int] IDENTITY (1, 1) NOT NULL , [SendCentreID] [int] NOT NULL , [Mo] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL , [Stat] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ) ON [PRIMARY] GO CMPP_SendCentreMo.SendCentreID 与CMPP_SendCentre.ID成外建关系于是建了一个视图代码如下:CREATE VIEW dbo.ViewCMPP_SendCentreMo AS SELECT dbo.CMPP_SendCentreMo.id免费主机域名, dbo.CMPP_SendCentreMo.SendCentreID, dbo.CMPP_SendCentreMo.Mo, dbo.CMPP_SendCentreMo.Stat, dbo.CMPP_SendCentre.SendType, dbo.CMPP_SendCentre.SendDate, dbo.CMPP_SendCentre.Port, dbo.CMPP_SendCentre.Service_ID, case dbo.CMPP_SendCentre.FeeType when ’01’ then ‘免费’ when ’02’ then ‘点播’ else ‘包月’ end as FeeType, cast(dbo.CMPP_SendCentre.FeeCode as smallint) as FeeCode, dbo.CMPP_SendCentre.Msg_Content FROM dbo.CMPP_SendCentre INNER JOIN dbo.CMPP_SendCentreMo ON dbo.CMPP_SendCentre.id = dbo.CMPP_SendCentreMo.SendCentreID一开始的查询语句为代码如下:
select top 6*from [ViewCMPP_SendCentreMo] where SendType = ‘扣费’ order by id desc发现非常的慢 经过了解,原因是order by id desc/asc的查询是一行一行的找数据,所以非常的慢 于是改成了代码如下:
select top 6*from [ViewCMPP_SendCentreMo] where SendType = ‘扣费’ order by SendCentreID desc, id desc查询就非常的快了上述内容就是SQL order by ID desc/asc加一个排序的字段解决查询慢问题的示例分析,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注云技术行业资讯频道。
相关推荐: mysqldump中参数net-buffer-length怎么用
这篇文章给大家分享的是有关mysqldump中参数net-buffer-length怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。 mysqldump的net-buffer-length有大师说mysqldump的net-bu…