简体   繁体   English

为什么在Access前端和SQL后端上使用复杂的SQL会比较慢?

[英]Why is complex SQL slow when used on Access front end and SQL Back-end?

I understand that in the case of complex queries with multiple join statements it is preferred to use pass through queries. 我了解在具有多个join语句的复杂查询的情况下,最好使用直通查询。 My confusion is on what happens when we do not use pass through query for complex sql statements. 我的困惑是当不对复杂的sql语句使用直通查询时会发生什么。

Is it slow because the ODBC driver cannot parse the query and SQL server cannot understand it and sends all the data through the network pipe to be queried by Access itself 是因为ODBC驱动程序无法解析查询并且SQL Server无法理解查询并通过要由Access本身查询的网络管道发送所有数据,所以它很慢吗?

OR 要么

Is it slow because even though ODBC driver can parse the SQL statement it takes a lot of time to do so 它是否很慢,因为即使ODBC驱动程序可以解析SQL语句,它也要花费很多时间

First of all, if a pass-through query is used with an ODBC driver, then Access itself makes no attempt to parse the query and instead just sends it to the database via the ODBC driver . 首先,如果传递查询与ODBC驱动程序一起使用,则Access本身不会尝试解析该查询 ,而是仅通过ODBC驱动程序将其发送到数据库。 In this way, one can submit queries using the native SQL dialect understood by the server. 这样,就可以使用服务器可以理解的本地SQL方言提交查询。 This allows specialized and/or highly optimized queries to be submitted that Access could not execute itself. 这允许提交Access无法执行的专门和/或高度优化的查询。 Futher, such queries can also refer to server tables (and other objects) that are not linked to Access. 此外,此类查询还可以引用未链接到Access的服务器表(和其他对象)。

In the case of a "normal" Access query (not a pass-through), the Access database engine will attempt to parse, interpret and optimize the query according to its own capabilities. 对于“普通” Access查询(不是传递),Access数据库引擎将尝试根据其自身的功能来解析,解释和优化查询。 In doing so, Access will construct one or multiple queries that it will send to the server also via the ODBC driver . 为此,Access将构造一个或多个查询,也将通过ODBC驱动程序将其发送到服务器。 Upon receiving the data from the server, it will then apply all residual joins and criteria to the data in order to satisfy the overall SQL statement-- this is done locally by Access, independent of the remote server . 从服务器收到数据后,它将对数据应用所有残留的联接和条件,以满足整体SQL语句- 这是由Access在本地完成的,独立于远程服务器

Just as others commented, sometimes Access might be smart enough to instruct the remote server to perform some joins or to apply some criteria (eg WHERE conditions), but the Access engine is not smart enough to always choose the best optimization. 就像其他人评论的那样,有时Access可能足够聪明,可以指示远程服务器执行某些联接或应用某些条件(例如WHERE条件),但是Access引擎不够聪明,无法始终选择最佳优化。 That is especially true when the query contains source tables both from Access tables and remote tables. 当查询同时包含Access表和远程表的源表时,尤其如此。 These limitations are precisely why the pass-through query exists as an option, so that the programmer can intervene in sending optimized queries to the server, then perform other joins and criteria later using additional Access queries. 这些限制正是为什么传递查询作为选项存在的原因,以便程序员可以干预将优化的查询发送到服务器,然后在以后使用其他Access查询执行其他联接和条件。

Thus, any query sent to the server must go through the ODBC driver. 因此,任何发送到服务器的查询都必须通过ODBC驱动程序。 It is correct that the ODBC driver will do some initial parsing of the statements so that it can handle parameters, etc., but statement parsing is only the beginning of an efficient database operation . 正确的是,ODBC驱动程序将对语句进行一些初始解析,以便它可以处理参数等,但是语句解析只是高效数据库操作的开始 A database engine stores detailed information about indices, constraints, relationships, etc. It uses such meta-data to retrieve, combine and sort data efficiently, but it does so by storing that meta-data along with the tables. 数据库引擎存储有关索引,约束,关系等的详细信息。它使用此类元数据来有效地检索,合并和排序数据,但是它通过将元数据与表一起存储来实现。 So a remote server will have all that meta-data on the remote server which Access cannot utilize. 因此,远程服务器将具有Access无法利用的所有元数据。 Access and SQL Server (and any other RDBMS) have different database engines and are not designed to exchange the underlying meta-data (eg indexes, constraints -- as mentioned before). Access和SQL Server(以及任何其他RDBMS)具有不同的数据库引擎,并且不旨在交换基础元数据(例如,索引,约束-如前所述)。 It is worth noting that sometimes minimal information can be specified, like primary keys, to assist Access in using remote tables more efficiently, but this is really minimal and will not provide guaranteed efficient data operations. 值得注意的是,有时可以指定最少的信息(例如主键)来帮助Access更有效地使用远程表,但这实际上是最少的,并且不能提供有保证的高效数据操作。


In response to the comment about query efficiency "after all these years"... 为了回应有关“多年来的查询效率”的评论,...

The fact is that Access is largely an older technology with very basic relational database capabilities built primarily for local databases. 事实是Access在很大程度上是一种较旧的技术,具有非常基本的关系数据库功能,主要为本地数据库构建。 It was never designed to be optimized for remote data operations. 它从未被设计为针对远程数据操作进行优化。 Furthermore, the underlying database engines of Access and SQL Server (or any other RDBMS) are not compatible. 此外,Access和SQL Server(或任何其他RDBMS)的基础数据库引擎不兼容。 They each have their own way of storing data and meta-data. 它们每个都有自己的存储数据和元数据的方式。 The only interoperability comes via SQL statements of which you are aware and which were discussed in the previous paragraphs. 唯一的互操作性来自您所知道的SQL语句,并且在前面的段落中已进行了讨论。 There is no standard SQL terms for exchanging the necessary complex meta-data for fully optimizing queries between Access and remote servers, at least not beyond standard JOINS and WHERE conditions. 没有标准的SQL术语来交换必要的复杂元数据以完全优化Access和远程服务器之间的查询,至少没有超出标准的JOINS和WHERE条件。

However, it is completely reasonable to expect progress over the years. 但是,期望这些年来的进展是完全合理的。 Advanced database servers--SQL Server included--do indeed support means of replicating data tables and other objects across remote servers. 先进的数据库服务器(包括SQL Server)确实支持跨远程服务器复制数据表和其他对象的方法。 In that case, highly efficient queries can be crafted which request data from tables that are distributed over multiple servers. 在这种情况下,可以设计出高效的查询,这些查询从分布在多个服务器上的表中请求数据。 So the ultimate answer to the expectation of progress would be to replace old technology like Access and implement newer, more complex and capable data servers. 因此,对进展的期望的最终答案将是替换诸如Access之类的旧技术,并实现更新,更复杂和功能强大的数据服务器。 This is not meant as a slight against Access, only a realization that Access will not change much at all even after many more years. 这并不意味着对Access有轻微的影响,只是意味着即使在使用了很多年之后,Access也不会有太大变化。 New data storage and retrieval technologies are being updated, not Access. 新的数据存储和检索技术正在更新,而不是Access。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 访问连接到 Azure SQL Server 后端的本地前端非常慢 - Access local front-end connected to Azure SQL Server back-end very slow 访问前端,SQL Server后端跳过自动编号ID - Access front-end, SQL Server back-end skipping autonumber IDs 将后端移动到 SQL 服务器后,Access 中的列排序非常慢 - Sorting columns is very slow in Access after moving back-end to SQL Server 使用MS Access链接表到SQL Server后端时是否可以进行SQL注入 - Is SQL injection possible when using MS Access linked tables to a SQL server back-end 将 MS Access 后端迁移到 SQL 服务器 - Migrate MS Access back-end to SQL Server 访问前端SQL后端安全连接 - Access front end SQL back end secure connection 将多用户访问前端连接到SQL Server后端 - Connecting a Multi User Access Front End to SQL Server Back End 使用SQL Server后端更新的MS Access失败,没有错误 - MS Access with SQL Server back-end update fails without error 用SQL Server后端替换Access中的查找贷款的有效方法 - Efficient way to replace find loan in Access with SQL Server back-end Access 2010应用程序,SQL Server 2008R2后端,抛出错误“无法找到字段” - Access 2010 application, SQL Server 2008R2 back-end, throwing error “Could not find field”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM