自己的应用程序内部的查询调用与高级数据库架构师之间的优化差异

发布于 2024-12-17 08:08:47 字数 1080 浏览 2 评论 0原文

我目前正在使用 sybase 的优势数据库服务器。我正在 delphi 中编程,并且使用本地服务器。我的问题是,如果我在自己的源代码中进行 sql 查询,则查询速度会慢 3 倍(特别是对于嵌套 Select 查询),就好像我也在 sybase 提供的 Advantage Database Architect 中使用完全相同的查询一样。 数据库也是一样的。我是否缺少任何优化步骤?

我的源代码如下所示:

  //Initializing Connection and Query
  FADSConnection.LoginPrompt := false;
  FADSConnection.ConnectPath := Filename;
  FADSConnection.AdsServerTypes := [stADS_LOCAL];
  FADSConnection.Name := 'ADB';
  FADSConnection.EncryptionOptions.DataEncryptionType := etAdsAES256;
  FADSConnection.IsConnected := true;


  FADSQuery.DatabaseName := FADSConnection.Name;
  FADSQuery.SourceTableType := ttAdsADT;
  FADSQuery.AdsTableOptions.AdsCharType := GERMAN_VFP_CI_AS_437;

  s := 'SELECT *' 
       + 'FROM ADB_Table1 WHERE No IN' 
       +'(SELECT No' 
       +       'FROM ADB_Table2 WHERE V=0.4 AND N=26 AND No IN' 
       +       '(SELECT No FROM ADB_Table2 WHERE V=0.6 AND N=8)) AND Count=2'

  FADSQuery.sql.Text := s;
  FADSQuery.Open;
  FADSQuery.first;

在我的程序中,查询需要 600 毫秒。在优势数据库架构师中,它需要 200 毫秒。该数据库约有 18000 个条目。

先感谢您!

I am working at the moment with the advantage database server from sybase. I am programming in delphi and I am using a local server. My problem is, if I make a sql query inside my own source code the query is 3 times slower (especially for nested Select queries) as if I would use exactly the same query inside the Advantage Database Architect delivered by sybase, too.
The database is also the same. Is there any optimization step I am missing?

My Source Code looks like this:

  //Initializing Connection and Query
  FADSConnection.LoginPrompt := false;
  FADSConnection.ConnectPath := Filename;
  FADSConnection.AdsServerTypes := [stADS_LOCAL];
  FADSConnection.Name := 'ADB';
  FADSConnection.EncryptionOptions.DataEncryptionType := etAdsAES256;
  FADSConnection.IsConnected := true;


  FADSQuery.DatabaseName := FADSConnection.Name;
  FADSQuery.SourceTableType := ttAdsADT;
  FADSQuery.AdsTableOptions.AdsCharType := GERMAN_VFP_CI_AS_437;

  s := 'SELECT *' 
       + 'FROM ADB_Table1 WHERE No IN' 
       +'(SELECT No' 
       +       'FROM ADB_Table2 WHERE V=0.4 AND N=26 AND No IN' 
       +       '(SELECT No FROM ADB_Table2 WHERE V=0.6 AND N=8)) AND Count=2'

  FADSQuery.sql.Text := s;
  FADSQuery.Open;
  FADSQuery.first;

The Query takes 600 ms in my program. In the advantage database architect it needs 200 ms. The database has around 18000 entries.

Thank you in advance!

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

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

发布评论

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

评论(1

笑红尘 2024-12-24 08:08:47

所以,我发现了我的错误:

问题是查询实例的初始化。
不知何故,不需要过度处理源表类型和 AdsCharType。

FADSQuery.SourceTableType := ttAdsAdt;
FADSQuery.Tableoptions.AdsCharType := GERMAN_VFP_CI_AS_437;

我刚刚删除了上面的行,我的查询几乎与 Advantage Data Architect 一样快。

So, I found my mistake:

The Problem is the initialization of the query instance.
Somehow overhanding of the Source Table Type and the AdsCharType isn't necessary.

FADSQuery.SourceTableType := ttAdsAdt;
FADSQuery.Tableoptions.AdsCharType := GERMAN_VFP_CI_AS_437;

I just removed the above lines and my queries are nearly as fast as the Advantage Data Architect.

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