草庐IT

mysql - 如何在 Perl 中提高此 MySQL 查询的性能,直接在 MySQL Workbench 中执行的相同查询快 1600 倍

coder 2023-10-24 原文

我在 Perl 中的 MySQL 查询比在 MySQL Workbench 中的相同查询花费的时间长得多。我正在尝试将 Perl 查询的性能提高到与 Workbench 查询大致相同的性能。
我在 Microsoft Windows 10 pro 64 位、ActivePerl 5.24.0 Build 2400 64 位、使用 DBI V1.636、DBD-MySQL 4.033 和 MySQL V5.7 64 位上运行。
我找不到任何资源限制。所以 InnoDB 缓冲池 – 40% 被利用。表打开缓存效率为 99%。 64GB RAM,16 个以 3.4Ghz 运行的处理器。 在此环境中运行的大多数查询速度都可以接受。有一类查询在 Perl 中运行得非常慢,但在 Workbench 中运行得相当快。这是查询的示例。

SELECT t1.CSI_ID, t2.Signal_Date, t2.NextGain   
    FROM        
        equity as t1    
    INNER JOIN      
        (equity_signal AS t2, market_boundary AS t3) 
ON 
(t2.equity_CSI_ID = t1.CSI_ID AND 
Yearweek(t3.Signal_Date)= Yearweek(t2.Signal_Date)) 
    WHERE       
        YearWeek(t2.Signal_Date) = 201643   
        AND t2.currency_idCurrency = 'USD'
        AND t1.UseEquity = 1
        AND t1.NoData = 0
        AND t2.Spike = 0
        AND t1.Exchange IN ('NYSE','NASDAQ')
        AND t2.Liquidity>t3.Value 
        AND t3.Currency='USD'
        AND t3.Market='US'
        AND t3.Type='LQ'
        AND t3.Threshold=500
        AND t2.StdDev < 1
        AND (t2.CalcBool & 63) = 63
    ORDER BY (t2.Buy) 
DESC LIMIT 50

这是查询成功执行时的解释图。 MySQL Workbench 中的这个查询用了 4.047 秒。

查询中的 T1 有 29000 行,14 列,大小为 3.5MB。 查询中的 T2 有 8500000 行、34 列和 1.7GB 以及 1.2GB 索引。 查询中的 T3 有 54000 行、7 列并且是 3.5 MB

Explain Statement Results from WorkBench

通过 Perl 执行时的解释语句结果如下,这与我刚从 Workbench 收到的表格结果相同:
1 SIMPLE t3 ref PRIMARY PRIMARY 38 const 27354 0.10 Using where;使用临时的;使用文件排序
1 SIMPLE t1 ALL PRIMARY 29304 0.20 Using where;使用连接缓冲区( block 嵌套循环)
1 SIMPLE t2 ref PRIMARY,Liquidity,Buy,StdDev PRIMARY 4 investing2.t1.CSI_ID 92 0.56 Using where

在执行查询期间,我的创建过程没有并发或竞争进程访问或使用相关表。 当我在 Perl 中运行相同的查询时,我让 MySQL 使用 13% 的可用 CPU(跨 16 个 CPU)超过 100 分钟。

案例 1,投资组合 = 11 年周 = 201644
PortDatah 开始于 2016 年 11 月 5 日星期六 14:47:00 结束于 2016 年 11 月 5 日星期六 16:33:23
投资组合 = 11 年周 = 201644
案例 1,投资组合 = 11 YearWeek = 201643
PortDatah 开始于 2016 年 11 月 5 日星期六 16:33:23 结束于 2016 年 11 月 5 日星期六 18:19:47

所以第一次运行时间为 106 分 23 秒,第二次运行时间为 106 分 24 秒。 在完全不同的平台(MySQL 5.5、32 GB RAM、Perl 5.16.3)上,相同代码的工作性能与 Workbench 观察到的结果相当。
以下是我认为相关的代码片段。

#!D:\perl64\bin
use strict;
use warnings;
use DBI;
use List::Util qw(first);
use threads;
use Date::Simple (':all');
use Switch::Plain;
my @Portfolio;
$Portfolio[11]="SELECT t1.CSI_ID, t2.Signal_Date, t2.NextGain   
    FROM        
        equity as t1    
    INNER JOIN      
        (equity_signal AS t2, market_boundary AS t3) 
ON (t2.equity_CSI_ID = t1.CSI_ID 
AND Yearweek(t3.Signal_Date)=Yearweek(t2.Signal_Date))  
    WHERE   
        YearWeek(t2.Signal_Date) = 201643   
        AND t2.currency_idCurrency = 'USD'
        AND t1.UseEquity = 1
        AND t1.NoData = 0
        AND t2.Spike = 0
        AND t1.Exchange IN ('NYSE','NASDAQ')
        AND t2.Liquidity>t3.Value 
        AND t3.Currency='USD'
        AND t3.Market='US'
        AND t3.Type='LQ'
        AND t3.Threshold=500
        AND t2.StdDev < 1
        AND (t2.CalcBool & 63) = 63
    ORDER BY (t2.Buy) 
DESC LIMIT 50";
my $thread11 = threads->create(\&PortfolioA,11,$Portfolio[11]);
my $return = $thread11->join();

sub PortfolioA {
my $PortID = shift;
    my $PortSQL = shift;
    my $PortDatah = $dbh->prepare($PortSQL)
        or die "Couldn't prepare statement: " . $dbh->errstr;
$Starttime=localtime();
    $PortDatah->execute($YearWeek)
        or die "Couldn't execute statement: " . $dbh->errstr;
    $Endtime=localtime();
    print "PortDatah Start $Starttime  End $Endtime \n";    

我在日志中查找错误,我尝试调整 MySQL 服务器。所以 InnoDB Buffer Pool 是 12 GB,Join Buffer Size 是 4GB,Sort Buffer Size 是 4GB,有 8 个 InnoDB page cleaners,Query Cache Size 是 2GB。我在 Signal_Date 上为 Equity_Signal 添加了一个索引,这是数据库中最大的表。 我正在考虑尝试安装以前版本的 Perl 和 MySQL,看看是否可以解决问题。我只是看不出我错过了什么。

这是使用跟踪级别 4 的单个查询的结果。

    DBI::st=HASH(0x3081000) trace level set to 0x0/4 (DBI @ 0x0/0) in DBI 1.636-ithread (pid 10776)
-> execute for DBD::mysql::st (DBI::st=HASH(0x3081318)~0x3081000 '201644') thr#26278d8
Called: dbd_bind_ph
-> dbd_st_execute for 03081360
>- dbd_st_free_result_sets
<- dbd_st_free_result_sets RC -1
<- dbd_st_free_result_sets
mysql_st_internal_execute MYSQL_VERSION_ID 50172
>parse_params statement SELECT t1.CSI_ID, t2.Signal_Date, t2.NextGain   
                        FROM        
                            equity as t1    
                        INNER JOIN      
                            (equity_signal AS t2, market_boundary AS t3) ON (t2.equity_CSI_ID = t1.CSI_ID AND Yearweek(t3.Signal_Date)=Yearweek(t2.Signal_Date))    
                        WHERE       
                            YearWeek(t2.Signal_Date) = ?    
                            AND t2.currency_idCurrency = 'USD'
                            AND t1.UseEquity = 1
                            AND t1.NoData = 0
                            AND t2.Spike = 0
                            AND t1.Exchange IN ('NYSE','NASDAQ')
                            AND t2.Liquidity>t3.Value 
                            AND t3.Currency='USD'
                            AND t3.Market='US'
                            AND t3.Type='LQ'
                            AND t3.Threshold=500
                            AND t2.StdDev < 1
                            AND (t2.CalcBool & 63) = 63
                        ORDER BY t2.Buy DESC        
                        LIMIT 50
Binding parameters: SELECT t1.CSI_ID, t2.Signal_Date, t2.NextGain   
                        FROM        
                            equity as t1    
                        INNER JOIN      
                            (equity_signal AS t2, market_boundary AS t3) ON (t2.equity_CSI_ID = t1.CSI_ID AND Yearweek(t3.Signal_Date)=Yearweek(t2.Signal_Date))    
                        WHERE       
                            YearWeek(t2.Signal_Date) = '201644' 
                            AND t2.currency_idCurrency = 'USD'
                            AND t1.UseEquity = 1
                            AND t1.NoData = 0
                            AND t2.Spike = 0
                            AND t1.Exchange IN ('NYSE','NASDAQ')
                            AND t2.Liquidity>t3.Value 
                            AND t3.Currency='USD'
                            AND t3.Market='US'
                            AND t3.Type='LQ'
                            AND t3.Threshold=500
                            AND t2.StdDev < 1
                            AND (t2.CalcBool & 63) = 63
                        ORDER BY t2.Buy DESC        
                        LIMIT 50
DBI::st=HASH(0x2f71530) trace level set to 0x0/4 (DBI @ 0x0/0) in DBI 1.636-ithread (pid 11064)
-> execute for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530 '201644') thr#25178d8
Called: dbd_bind_ph
-> dbd_st_execute for 02f71890
>- dbd_st_free_result_sets
<- dbd_st_free_result_sets RC -1
<- dbd_st_free_result_sets
mysql_st_internal_execute MYSQL_VERSION_ID 50172
>parse_params statement SELECT t1.CSI_ID, t2.Signal_Date, t2.NextGain   
                        FROM        
                            equity as t1    
                        INNER JOIN      
                            (equity_signal AS t2, market_boundary AS t3) ON (t2.equity_CSI_ID = t1.CSI_ID AND Yearweek(t3.Signal_Date)=Yearweek(t2.Signal_Date))    
                        WHERE       
                            YearWeek(t2.Signal_Date) = ?    
                            AND t2.currency_idCurrency = 'USD'
                            AND t1.UseEquity = 1
                            AND t1.NoData = 0
                            AND t2.Spike = 0
                            AND t1.Exchange IN ('NYSE','NASDAQ')
                            AND t2.Liquidity>t3.Value 
                            AND t3.Currency='USD'
                            AND t3.Market='US'
                            AND t3.Type='LQ'
                            AND t3.Threshold=500
                            AND t2.StdDev < 1
                            AND (t2.CalcBool & 63) = 63
                        ORDER BY t2.Buy DESC        
                        LIMIT 50
Binding parameters: SELECT t1.CSI_ID, t2.Signal_Date, t2.NextGain   
                        FROM        
                            equity as t1    
                        INNER JOIN      
                            (equity_signal AS t2, market_boundary AS t3) ON (t2.equity_CSI_ID = t1.CSI_ID AND Yearweek(t3.Signal_Date)=Yearweek(t2.Signal_Date))    
                        WHERE       
                            YearWeek(t2.Signal_Date) = '201644' 
                            AND t2.currency_idCurrency = 'USD'
                            AND t1.UseEquity = 1
                            AND t1.NoData = 0
                            AND t2.Spike = 0
                            AND t1.Exchange IN ('NYSE','NASDAQ')
                            AND t2.Liquidity>t3.Value 
                            AND t3.Currency='USD'
                            AND t3.Market='US'
                            AND t3.Type='LQ'
                            AND t3.Threshold=500
                            AND t2.StdDev < 1
                            AND (t2.CalcBool & 63) = 63
                        ORDER BY t2.Buy DESC        
                        LIMIT 50
 <- dbd_st_execute returning imp_sth->row_num 19
    <- execute= ( 19 ) [1 items] at C:/workspace/DIY Investing/CSI/I2Portfolio1debug.pl line 873 via  at C:/workspace/DIY Investing/CSI/I2Portfolio1debug.pl line 700
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=19
    dbd_st_fetch for 02f71890, currow= 1
    <- dbd_st_fetch, 3 cols
    <- fetchrow_array= ( '9825' '2016-11-04' '0' ) [3 items] row1 at C:/workspace/DIY Investing/CSI/I2Portfolio1debug.pl line 878 via  at C:/workspace/DIY Investing/CSI/I2Portfolio1debug.pl line 700
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 2
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 3
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 4
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 5
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 6
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 7
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 8
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 9
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 10
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 11
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 12
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 13
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 14
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 15
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 16
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 17
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 18
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 19
    <- dbd_st_fetch, 3 cols
    -> fetchrow_array for DBD::mysql::st (DBI::st=HASH(0x2f71848)~0x2f71530) thr#25178d8
    -> dbd_st_fetch
        dbd_st_fetch for 02f71890, chopblanks 0
    dbd_st_fetch result set details
    imp_sth->result=03a71110
    mysql_num_fields=3
    mysql_num_rows=19
    mysql_affected_rows=1
    dbd_st_fetch for 02f71890, currow= 20
    dbd_st_fetch, no more rows to fetch
--> dbd_st_finish
    >- dbd_st_free_result_sets
    <- dbd_st_free_result_sets RC -1
    <- dbd_st_free_result_sets

我将尝试重新处理查询以避免 Yearweek(我使用 Yearweek,因为数据是每周的,但有时周五作为最后一天,有时作为周四,我想比较市场之间的周 -只是不在此查询示例中),但我也应该能够使用 Interval。此外,我正在考虑在 Python 或 Ruby 中尝试这整个过程,而不是安装后台产品。

以下是每个表的创建表条目:

t1 - 权益

CREATE TABLE `equity` (
  `CSI_ID` int(11) NOT NULL,
  `Symbol` varchar(45) NOT NULL,
  `EquityName` varchar(45) NOT NULL,
  `Exchange` varchar(45) NOT NULL,
  `currency_idCurrency` varchar(6) NOT NULL,
  `PriceForm` int(11) DEFAULT NULL,
  `StartDate` date DEFAULT NULL,
  `LastUpdate` date DEFAULT NULL,
  `industry_idSector` varchar(10) NOT NULL,
  `industry_idIndustry` varchar(10) NOT NULL,
  `NoData` tinyint(1) NOT NULL DEFAULT '0',
  `UseEquity` tinyint(1) NOT NULL DEFAULT '1',
  `Category` varchar(10) DEFAULT NULL,
  `OutShares` float DEFAULT NULL,
  PRIMARY KEY (`CSI_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

t2 equity_signal(我没有在此表中显示未使用的列)

CREATE TABLE `equity_signal` (
  `equity_CSI_ID` int(11) NOT NULL,
  `Signal_Date` date NOT NULL,
  `currency_idCurrency` varchar(6) NOT NULL,
  `Signal_Sequence` int(11) NOT NULL,
  `Adjusted_Close` float NOT NULL,
  `Liquidity` float NOT NULL,
  `Gain` float NOT NULL,
  `NextGain` float DEFAULT NULL,
  `StdDev` double NOT NULL,
  `Spike` tinyint(1) NOT NULL,
  `Buy` float NOT NULL,
  `CalcBool` int(11) NOT NULL,
  PRIMARY KEY (`equity_CSI_ID`,`Signal_Date`,`currency_idCurrency`),
  KEY `Liquid` (`currency_idCurrency`,`Signal_Date`,`Liquidity`),
  KEY `Buy` (`currency_idCurrency`,`Signal_Date`,`Buy`),
  KEY `STD` (`currency_idCurrency`,`Signal_Date`,`StdDev`),
  KEY `Signal_Date` (`Signal_Date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

并且 t3 作为 market_boundary

CREATE TABLE `market_boundary` (
  `Market` varchar(12) NOT NULL,
  `Signal_Date` date NOT NULL,
  `Currency` varchar(6) NOT NULL,
  `Type` varchar(6) NOT NULL,
  `Threshold` int(11) NOT NULL,
  `Percent` float NOT NULL,
  `Value` float NOT NULL,
  PRIMARY KEY (`Market`,`Signal_Date`,`Currency`,`Type`,`Threshold`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

最佳答案

yearweek 测试更改为

WHERE Signal_date >= '2016-10-22'
  AND Signal_date  < '2016-10-22' + INTERVAL 1 WEEK

(或任何正确的日期。)

并以这种方式分别检查测试 t3.Signal_datet2.Signal_date

然后在每个表上构建一个合适的复合索引——以 Signal_date 结尾。

看了SHOW CREATE TABLE之后,我可能会有更多的建议。

回到您的问题……对于为什么一个客户端运行得比另一个客户端快得多,我没有一个好的答案。 (我的缓存评论不足以解释 1600x。)但是,修复索引应该对两个客户端都有帮助,也许超过 1600x。

关于mysql - 如何在 Perl 中提高此 MySQL 查询的性能,直接在 MySQL Workbench 中执行的相同查询快 1600 倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40444785/

有关mysql - 如何在 Perl 中提高此 MySQL 查询的性能,直接在 MySQL Workbench 中执行的相同查询快 1600 倍的更多相关文章

  1. ruby - 如何在 Ruby 中顺序创建 PI - 2

    出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits

  2. ruby - ECONNRESET (Whois::ConnectionError) - 尝试在 Ruby 中查询 Whois 时出错 - 2

    我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.

  3. ruby - 如何将脚本文件的末尾读取为数据文件(Perl 或任何其他语言) - 2

    我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚

  4. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  5. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  6. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  7. ruby - 如何在续集中重新加载表模式? - 2

    鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende

  8. ruby - 如何在 Ruby 中拆分参数字符串 Bash 样式? - 2

    我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"

  9. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

    我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

  10. ruby-on-rails - 如何在 ruby​​ 交互式 shell 中有多行? - 2

    这可能是个愚蠢的问题。但是,我是一个新手......你怎么能在交互式ruby​​shell中有多行代码?好像你只能有一条长线。按回车键运行代码。无论如何我可以在不运行代码的情况下跳到下一行吗?再次抱歉,如果这是一个愚蠢的问题。谢谢。 最佳答案 这是一个例子:2.1.2:053>a=1=>12.1.2:054>b=2=>22.1.2:055>a+b=>32.1.2:056>ifa>b#Thecode‘if..."startsthedefinitionoftheconditionalstatement.2.1.2:057?>puts"f

随机推荐