In the process of making a report, there is a report to query the exchange rate of the corresponding currency, and the exchange rate in another table, and the criteria for querying the exchange rate is based on the statistical date of the report (page passed in parameters), to the exchange rate table for the date of the last one months of exchange rates, if there is no previous month's exchange rate , therefore, a function that gets the exchange rate is customized, put in SQL, its incoming parameter is the corresponding currency code and the statistic date, so that this function has no way to establish the function index, which causes the query result is very slow, 1.5 million of the data export takes more than 10 minutes.
Later, because the statistical date is determined, the corresponding exchange rate is determined, so another exchange rate table, the exchange rate is what we want to exchange rate, we query the page when the execution of the stored procedure, we want the currency and the corresponding exchange rate to deposit the table.
We simply query the exchange rate of the corresponding currency in the table in the SQL statement, and no longer need to call the function that gets the exchange rate, so the speed is much faster and the time is shortened by almost half.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Solutions that result in slow SQL queries for custom functions