English 中文(简体)
Jet Engine s query-optimization is based on statistics, but how are they refreshed with linked tables?
原标题:

i am dealing with some legacy access < 2007 "databases". All the tables are linked tables to a SQL Server 2008. While the odbc-links are established the table structure is copied into the mdb-file together with the DSN-string. Thats what one can see in Msysobjects.

A query forces the jet-engine to retrieve the data from SQL Server under respect of the jet-engines optimization. Therefore it is essential to refresh the odbc-links whenever a change in sql server is made, like adding a new index par example too.

As some tables grow larger the jet-optimizer needs refreshed statistics but which process does that? Is it Repair & Compact or refreshing the ODBC-Links? Can this be done programatically?

Peace

Ice

最佳回答

The most important thing that JET needs to make good optimisation decisions is correct indices on tables. You can check what indices are visible to JET by opening a linked tables (ODBC) in design mode and clicking on the indices icon. You will get a warning to say that the tables are read-only.

Creating indices on source tables is likely to be more effective that waiting for JET to build up optimisation meta data when queries are executed.

问题回答

It s important to realize that only certain types of table statistics and metadata for ODBC data sources are going to be relevant to Jet. In general, I think the indexes are the only part that really matters from the standpoint of Jet deciding what to do with a SQL statement -- as long as the indexes are there and it understands the server on the other end, it will hand everything over to the server to process unless you ve foolishly selected or sorted on an expression that the server database can t understand. In that case, Jet may still be smart enough to send parts of the SQL statement for processing by the server (such as joins and criteria on literals), and then use the result set returned with the expression.

In regard to the question about linked tables, thouh, unfortunately, there is no dynamic way to update ODBC linked tables -- for instance, add a column to a table or view and it won t be in the table returned, refresh the link and the new column will appear, but it might be read-only.

I have found that the only thing to do when changing your server s table structures and views is to simply delete and recreate the relevant linked tables. I don t know that there s any programmatic way to do this. If there s any metadata about the table/view that tells when its structure was last updated, you might be able to check that against the date of the linked table, and delete and recreate when the back end has been updated after the link, but I m just guessing here. But that would be back-end specific.

For completeness sake, I ll just give the basics with a Jet back end:

With Access to Jet, a compact should reset the table stats, and upon the next run of each SQL statement, the compilation for each statement will be discarded and the query plan recalculated based on the new stats. It s important if you re compacting a front end for the purpose of updating table stats that you compact the back end before you compact the front end, because that insures that all the back-end table stats are as accurate as possible (though most of them stay up-to-date even without a compact).

I’m sure I will be corrected if I am wrong but I thought that re-linking the tables forced the statistics to be updated. If it is only a few tables then you could use the built in “Linked table manager” to do this. If not then you could automate it in code and then just fire off that function every time you wanted to update the table statistics.

I have some code that relinks access tables to other paths that I m sure you could modify to work with ODBC linked tables





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

access query to filter and combine count

i have two access tables tableA num count 1 7 2 8 3 9 4 9 5 13 6 6 tableB num count 0 1 1 14 2 12 3 5 4 5 5 11 6 5 how can i create an access query that ...

How to show File Picker dialog in Access 2007?

I want to show a dialog where the user can pick a file, click OK, and then the path to the file will be saved in the database. I have just one problem, I can t figure out how tho show the dialog ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

Returning row number on MS Access

I have 4 tables, from which i select data with help of joins in select query...I want a serial no.(row number) per record as they are fetched. first fetched record should be 1, next 2 and so on... In ...

热门标签