简体   繁体   中英

How can I check if a sql query is deterministic?

What I mean by deterministic is that the query will always return exactly the same result set. Is there a way to do this?

Queries aren't typically considered to be deterministic as the underlying tables can change between invocations. Determinism typically only comes into play when talking about UDFs.

The only way I know of to produce deterministic data in a database is to create a snapshot of the necessary data at the appropriate point in time. Usually, data is transformed and loaded into a data warehouse, along with a timestamp for the rows being archived, for later retrieval. Auditing and other kinds of reporting queries may be run against the data warehouse, and the results are "deterministic" for any given time period, but not across time periods.

Information housed in a data warehouse may also be precomputed into a multi-dimensional cube for faster processing, if necessary. To maintain proper form, data warehouse tables should only ever be inserted into, and new batches of data should always be associated with a unique timestamp. It is usually best to store data in some form of star or snowflake schema , which facilitates generation of a cube if necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM