日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 视图 查询速度慢_mysql 视图查询速度慢

發(fā)布時(shí)間:2023/12/15 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 视图 查询速度慢_mysql 视图查询速度慢 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

場景:

表?stockpooldata_flash

CREATE TABLE `stockpooldata_flash` (

`id` bigint(15) NOT NULL AUTO_INCREMENT,

`formula_id` int(8) DEFAULT NULL,

`period_type` tinyint(3) DEFAULT NULL,

`gpMarket` int(4) DEFAULT NULL,

`gpcode` varchar(20) DEFAULT NULL,

`ymd` int(11) DEFAULT NULL,

`hms` int(11) DEFAULT NULL,

`f1` decimal(18,4) DEFAULT NULL,

`f2` decimal(18,4) DEFAULT NULL,

`f3` decimal(18,4) DEFAULT NULL,

`f4` decimal(18,4) DEFAULT NULL,

`f5` decimal(18,4) DEFAULT NULL,

`f6` decimal(18,4) DEFAULT NULL,

`f7` decimal(18,4) DEFAULT NULL,

`f8` decimal(18,4) DEFAULT NULL,

`f9` decimal(18,4) DEFAULT NULL,

`f10` decimal(18,4) DEFAULT NULL,

`f11` decimal(18,4) DEFAULT NULL,

`f12` decimal(18,4) DEFAULT NULL,

`f13` decimal(18,4) DEFAULT NULL,

`f14` decimal(18,4) DEFAULT NULL,

`f15` decimal(18,4) DEFAULT NULL,

`f16` decimal(18,4) DEFAULT NULL,

`buyPrice` decimal(18,4) DEFAULT NULL,

`rise_max` decimal(18,4) DEFAULT NULL,

`rise_signalDay` decimal(18,4) DEFAULT NULL,

`high_max` decimal(18,4) DEFAULT NULL,

`yClose_signalDay` decimal(18,4) DEFAULT NULL,

`iTime` bigint(15) DEFAULT NULL,

`MaxRise` decimal(18,4) DEFAULT NULL,

`Rise_NextDay` decimal(18,4) DEFAULT NULL,

`MaxRise_NextDay` decimal(18,4) DEFAULT NULL,

`Rise_FiveDays` decimal(18,4) DEFAULT NULL,

`MaxRise_FiveDays` decimal(18,4) DEFAULT NULL,

`Rise_TenDays` decimal(18,4) DEFAULT NULL,

`MaxRise_TenDays` decimal(18,4) DEFAULT NULL,

`dayNum` int(8) DEFAULT '-1',

`tag` varchar(1024) DEFAULT NULL,

`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

PRIMARY KEY (`id`),

UNIQUE KEY `index_formulaId_gpcode_ymd` (`formula_id`,`period_type`,`ymd`,`gpMarket`,`gpcode`,`f10`) USING BTREE,

KEY `index_formulaId_period_ymd` (`formula_id`,`period_type`,`ymd`) USING BTREE,

KEY `index_formulaId_ymd` (`formula_id`,`ymd`) USING BTREE,

KEY `index_uptime` (`update_time`) USING BTREE

) ENGINE=InnoDB AUTO_INCREMENT=88197314 DEFAULT CHARSET=utf8;

建立了一個(gè)視圖 v_stockpooldata_flash

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_stockpooldata_flash` AS select

case formula_id

when '4' then 'DXJJ'

else `t`.`formula_id`

end

AS `gscode`,concat(convert(if((`t`.`gpMarket` = 0),'SZ','SH') using utf8),`t`.`gpcode`) AS `gpcode`,`t`.`ymd` AS `ymd`,

( floor(`t`.`hms` / 10000) * 60 + floor(`t`.`hms` % 10000 / 100) ) AS `hms`,

`t`.`f1` AS `f1`, `t`.`f2` AS `f2`, `t`.`f3` AS `f3`, `t`.`f4` AS `f4`, `t`.`f5` AS `f5`, `t`.`f6` AS `f6`,

case

when formula_id = 4 then ( floor(`t`.`f7` / 10000) * 60 + floor(`t`.`f7` % 10000 / 100) )

else `t`.`f7` end

AS `f7`,

`t`.`f8` AS `f8`, `t`.`f9` AS `f9`, `t`.`f10` AS `f10`, `t`.`f11` AS `f11`, `t`.`f12` AS `f12`, `t`.`f13` AS `f13`, `t`.`f14` AS `f14`, `t`.`f15` AS `f15`, `t`.`f16` AS `f16`, `t`.`rise_max` AS `rise_max`, `t`.`rise_signalDay` AS `rise_signalDay`, `t`.`high_max` AS `high_max`, `t`.`yClose_signalDay` AS `yClose_signalDay`, `t`.`update_time` AS `update_time`

from `stockpooldata_flash` `t`

“SELECT * FROM v_stockpooldata_flash where gscode = 'DXJJ' and ymd = 20190123” 語句查詢速度太慢:耗時(shí) 256.445 s

解決方法:利用源表中的索引?KEY `index_formulaId_period_ymd`

在創(chuàng)建視圖時(shí),select??`t`.`formula_id` AS `formula_id`

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_stockpooldata_flash` AS select `t`.`formula_id` AS `formula_id`,

case formula_id

when '4' then 'DXJJ'

else `t`.`formula_id`

end

AS `gscode`,concat(convert(if((`t`.`gpMarket` = 0),'SZ','SH') using utf8),`t`.`gpcode`) AS `gpcode`,`t`.`ymd` AS `ymd`,

( floor(`t`.`hms` / 10000) * 60 + floor(`t`.`hms` % 10000 / 100) ) AS `hms`,

`t`.`f1` AS `f1`, `t`.`f2` AS `f2`, `t`.`f3` AS `f3`, `t`.`f4` AS `f4`, `t`.`f5` AS `f5`, `t`.`f6` AS `f6`,

case

when formula_id = 4 then ( floor(`t`.`f7` / 10000) * 60 + floor(`t`.`f7` % 10000 / 100) )

else `t`.`f7` end

AS `f7`,

`t`.`f8` AS `f8`, `t`.`f9` AS `f9`, `t`.`f10` AS `f10`, `t`.`f11` AS `f11`, `t`.`f12` AS `f12`, `t`.`f13` AS `f13`, `t`.`f14` AS `f14`, `t`.`f15` AS `f15`, `t`.`f16` AS `f16`, `t`.`rise_max` AS `rise_max`, `t`.`rise_signalDay` AS `rise_signalDay`, `t`.`high_max` AS `high_max`, `t`.`yClose_signalDay` AS `yClose_signalDay`, `t`.`update_time` AS `update_time`

from `stockpooldata_flash` `t`

查詢語句改為“SELECT * FROM v_stockpooldata_flash where formula_id = 4 and ymd = 20190123” 查詢效果如下:耗時(shí) 0.962 s

來源:oschina

鏈接:https://my.oschina.net/u/4328407/blog/3660932

總結(jié)

以上是生活随笔為你收集整理的mysql 视图 查询速度慢_mysql 视图查询速度慢的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。