如何提高Windows XP中MYSQL ODBC 3.51驱动程序的速度?

发布于 2024-12-08 18:31:28 字数 1289 浏览 1 评论 0原文

I have a simple table with 3 records in it. Doing a select * from table with ODBC in C#.NET is extremely slow, on the magnitude of 20 seconds or more.

如何提高Windows XP中MYSQL ODBC 3.51驱动程序的速度?

这是查询:

public static string sTableQueryUngroup = 
  " (SELECT
       *
       ,(SELECT unit_param_desc 
         FROM tr_config_unit_params 
         WHERE unit_param_id={TABLE_NAME}.unit_param_id 
           AND unit_id={UNIT_ID}) as unit_param_desc 
     FROM {TABLE_NAME} 
     WHERE unit_param_id IN 
       (SELECT unit_param_id 
        FROM tr_config_unit_params 
        WHERE unit_id={UNIT_ID}) " + " 
        AND " + " {COLUMN_NAME} " + " BETWEEN '{FROM_DATE}' and '{TO_DATE}')";

我的第一个表 tr_config_unit_params 结构

unit_param_id 
unit_id  
unit_param_desc   
unit_param_opc_progid  
unit_param_host    
unit_param_link   
unit_param_data_type  
unit_param_type   
groupID    
tagID    

我的第二个表(日期方面)r20111010

         `unit_param_id` 
         `param_value` 
         `OPC-date ` 
         `param_quality` 
         `PC_date_logged` 

我已使用第一个表(tr_config_unit_params)列中的两个表unit_param_id与另一个表(r20111010)unit_param_id&匹配选择两个日期之间的数据(按 PC_date_logged 或 OPC-date 排序)。我想从表中选择特定的单元(如集合组)ID 信息。

I have a simple table with 3 records in it. Doing a select * from table with ODBC in C#.NET is
extremely slow, on the magnitude of 20 seconds or more.

how to improve the speed of the MYSQL ODBC 3.51 driver in windows XP?

Here's the query:

public static string sTableQueryUngroup = 
  " (SELECT
       *
       ,(SELECT unit_param_desc 
         FROM tr_config_unit_params 
         WHERE unit_param_id={TABLE_NAME}.unit_param_id 
           AND unit_id={UNIT_ID}) as unit_param_desc 
     FROM {TABLE_NAME} 
     WHERE unit_param_id IN 
       (SELECT unit_param_id 
        FROM tr_config_unit_params 
        WHERE unit_id={UNIT_ID}) " + " 
        AND " + " {COLUMN_NAME} " + " BETWEEN '{FROM_DATE}' and '{TO_DATE}')";

my first table tr_config_unit_params structure

unit_param_id 
unit_id  
unit_param_desc   
unit_param_opc_progid  
unit_param_host    
unit_param_link   
unit_param_data_type  
unit_param_type   
groupID    
tagID    

my second table (date wise) r20111010

         `unit_param_id` 
         `param_value` 
         `OPC-date ` 
         `param_quality` 
         `PC_date_logged` 

i have used the two tables from the first table(tr_config_unit_params ) column unit_param_id match with another table(r20111010) unit_param_id & select the data between two dates(sorted by PC_date_logged or OPC-date ). I want to select particular unit (like group of collection)ID information from the table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人海汹涌 2024-12-15 18:31:28

您的问题出在 SQL 而不是 ODBC 驱动程序很容易确定,只需使用不使用 ODBC 驱动程序的本机 MySQL 工具直接尝试查询即可。

我确信您会发现在没有驱动程序的情况下查询运行同样缓慢(在这种情况下,驱动程序的作用很小)。

我想说问题出在你的查询上 - 我发现它非常冗长,并且真的不明白为什么你要这样运行它,尽管你的语法使得很难准确地决定你想要做什么,据我所知该查询可以表达为两个表之间的简单闭合连接,而无需任何子选择。

在这种情况下,删除子选择将从根本上提高您的性能。除此之外,请查看 @duffymo'S anwser 并使用 EXPLAIN 来查看一些适当的索引可能对您有帮助。

That your problem is with the SQL and not with the ODBC driver is easy to establish, just try the query directly using an native MySQL tool which does not use the ODBC driver.

I am sure that you will find you query running equally slowly without the driver (which in a case such as this does very little).

I would say the problem is with your query - I find it extremely verbose and don't really see why you are running it this way, although your syntax makes it difficult to decide exactly what you are trying to do as far as I can see this query can be expressed and a simple closed join between two tables with out EITHER of the sub-selects.

Removing the sub-selects will radically increase you performance in this case. Beyond that take a look at @duffymo'S anwser and use EXPLAIN to see where some approriate indexes might help you.

水晶透心 2024-12-15 18:31:28

在责怪司机之前我会先看看你的询问。

解释计划并查看查询速度慢的地方。如果您看到 TABLE SCAN,那就是您的责任了。

确保 WHERE 子句中的变量应用了索引。

I'd look at your query before I'd blame the driver.

EXPLAIN PLAN and see where your query is slow. If you see TABLE SCAN, it's on you.

Make sure variables in WHERE clauses have indexes applied.

℡Ms空城旧梦 2024-12-15 18:31:28

首先 - 尝试重写您的查询,使用 JOIN 更改子查询,例如 -

SELECT *, p.unit_param_desc FROM <TABLE_NAME> t
  JOIN (SELECT * FROM tr_config_unit_params WHERE unit_id = <unit>) p
    ON t.unit_param_id = p.unit_param_id 
WHERE <COLUMN_NAME> BETWEEN <'{FROM_DATE}'> and <'{TO_DATE}'>;

...更改括号中的文本 <...>具有精确值。

Firstly - try to rewrite your query, change subquery with JOIN, for example -

SELECT *, p.unit_param_desc FROM <TABLE_NAME> t
  JOIN (SELECT * FROM tr_config_unit_params WHERE unit_id = <unit>) p
    ON t.unit_param_id = p.unit_param_id 
WHERE <COLUMN_NAME> BETWEEN <'{FROM_DATE}'> and <'{TO_DATE}'>;

...change texts in brackets <...> with exact values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文