小编Stu*_*eld的帖子

解释MySQL解释执行计划的数学,两个计划之间的区别

我有一个与解释相关的基本MySQL性能问题.我有两个返回相同结果的查询,我试图了解如何理解EXPLAIN执行计划.

该表中有50000条记录,我正在进行记录比较.我的第一个查询需要18.625秒才能运行.解释计划如下.

id  select_type table   type    possible_keys                   key         key_len ref                                 rows    filtered    Extra
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
1   SIMPLE      a       ALL     NULL                            NULL        NULL    NULL                                49520   100.00  
1   SIMPLE      b       ref     scoreEvent,eventScore           eventScore  4       olympics.a.eventId                  413     100.00      Using where; Using index; Not exists
1   SIMPLE      c       ref     PRIMARY,scoreEvent,eventScore   scoreEvent  8       olympics.a.score,olympics.a.eventId 4       100.00      Using where; Using index; Not exists
Run Code Online (Sandbox Code Playgroud)

我的下一个查询需要0.106秒才能运行...

id  select_type table       type    possible_keys   key     key_len     ref     rows    filtered    Extra
-----------------------------------------------------------------------------------------------------------------------------------
1   PRIMARY     <derived2>  ALL     NULL            NULL    NULL        NULL    50000 …
Run Code Online (Sandbox Code Playgroud)

mysql performance explain sql-execution-plan

10
推荐指数
1
解决办法
2877
查看次数

从CFC中包含CFM时的并发和范围问题

我在我的应用程序范围中放置一个组件,以便在所有请求中共享它,它包含一个cfm模板:

<cfcomponent output="false">

    <cffunction name="run" output="false" returntype="void">

        <cfset var tmp = false/>

        <cftry>
            <cfinclude template="inc.cfm"/>
            <cfcatch>
                <cffile action="append"
                        file="#ExpandPath("error.log")#"
                        output="ERROR: #cfcatch.message#"/>
            </cfcatch>
        </cftry>

    </cffunction>

</cfcomponent>
Run Code Online (Sandbox Code Playgroud)

正在包含的模板只是创建一个数组并检查数组长度应该是什么,如果不是它写入error.log文件:

<cfset tmp = [
    "one",
    "two",
    "three"
]/>
<cfif ArrayLen(tmp) neq 3>
    <cffile action="append"
            file="#ExpandPath("error.log")#"
            output="Length = #ArrayLen(tmp)#"/>
</cfif>
Run Code Online (Sandbox Code Playgroud)

如果我然后在它上面运行一个加载(100个并发线程),我会在我的error.log文件中出现以下项目...

ERROR: element at position 3 of array variable &quot;___IMPLICITARRYSTRUCTVAR0&quot; cannot be found.
Length = 0
Length = 2
Run Code Online (Sandbox Code Playgroud)

注意我在Java 1.7.0_09上使用ColdFusion 9.0.1.274733.我在相同的JRE上测试过Railo并且工作正常.


附加以下还会导致问题,将tmp变量更改为结构并在variables范围中添加随机项,而不是在任何地方引用...

<cfcomponent output="false"> …
Run Code Online (Sandbox Code Playgroud)

coldfusion cfc coldfusion-9

6
推荐指数
1
解决办法
246
查看次数

在C++中组织特定于平台的代码的推荐方法是什么?

如果我想为多个平台编写我的C++应用程序,例如Windows和Linux,那么编写平台代码的推荐方法是什么?有什么模式,类层次结构等来完成这项任务?我应该如何组织我的代码,标题和源文件?

c++ cross-platform

5
推荐指数
2
解决办法
1408
查看次数

慢查询ColdFusion,SQL Server,依赖于空格

我们有一个问题,我们从ColdFusion 9调用SQL Server 2005.我无法发布原始查询但它不是问题的焦点,我已经发布了导致问题的相关组合.

我们有一个查询,它是以下示例查询的一个更复杂的版本,其中something列是主键.value参数不会更改.由于我们无法理解的一些奇怪的原因,这个查询需要大约20秒才能运行....

<cfquery result="q" datasource="dsn">
  SELECT something
  FROM somewhere
  WHERE something = <cfqueryparam cfsqltype="cf_sql_integer" value="#value#"/> 
</cfquery>
Run Code Online (Sandbox Code Playgroud)

请注意,如果您突出显示上面的源代码的最后一行,则在cfqueryparam标记之后有一个空格.

以下查询完全不同,因为我相信您可以自己查看,需要15毫秒才能运行.

<cfquery result="q" datasource="dsn">
  SELECT something
  FROM somewhere
  WHERE something = <cfqueryparam cfsqltype="cf_sql_integer" value="#value#"/>
</cfquery>
Run Code Online (Sandbox Code Playgroud)

cfqueryparam之后没有空格.但是,在末尾添加两个空格也会产生15 ms.如果我们然后返回到最后一个空格再次给我们大约20秒的结果.

我们已经检查了Java和SQL Server之间的数据库驱动程序日志,似乎没有什么不寻常的.这可能发生什么?


编辑

我们在SQL Server上运行了分析,它表明对于具有单个空间的查询,它使用的是具有零或多个空格的不同缓存执行计划.SQL Server缓存查询的执行计划.它还使用完整的文字查询作为标识符.因此,当我们发送其他查询时,正在使用不同的执行计划.

进一步

其中一个执行计划看起来正在查找其中一个子选择上的错误索引,不清楚为什么SQL Server已经决定了这个备用执行计划,或者为什么看起来其中一个索引是错误的.

跟进

对于那些可能导致糟糕的执行计划感兴趣的人,后续问题发布在这里:SQL Server 2005缓存了一个永远不会工作的执行计划

sql-server coldfusion performance

5
推荐指数
1
解决办法
1542
查看次数

该项目存在于数组中,但它表示该数组的长度为0?

我可以将一个项目添加到数组中,我可以访问该项目,但length报告0.为什么?

var arr = [];
arr[4294967300] = "My item";
console.log(arr[4294967300], arr.length); // Outputs "My item", 0
Run Code Online (Sandbox Code Playgroud)

javascript

4
推荐指数
1
解决办法
103
查看次数

如何在MySQL中找到每个事件的最佳分数?

我有一个MySQL表,其中包含运动员进行的一系列测试的数据.我想为每个活动获得最好的结果.

这是包含运动员所有测试数据的表格:

+---------+-----------+-------+
| eventId | athleteId | score |
+---------+-----------+-------+
| 1       | 129907    | 900   |
| 2       | 129907    | 940   |
| 3       | 129907    | 927   |
| 4       | 129907    | 856   |
| 1       | 328992    | 780   |
| 2       | 328992    | 890   |
| 3       | 328992    | 936   |
| 4       | 328992    | 864   |
| 1       | 492561    | 899   |
| 2       | 492561    | 960 …
Run Code Online (Sandbox Code Playgroud)

mysql aggregate-functions

1
推荐指数
1
解决办法
184
查看次数