May 2018
Intermediate to advanced
576 pages
30h 25m
English
Where some queries access a table, replace that with a view that retrieves fewer rows using a TABLESAMPLE clause. In this example, we use a sampling method that produces a sample of the table using a scan lasting no longer than 5 secs; if the table is small enough the answer is exact - otherwise progressive sampling is used to ensure that we meet out time objective:
CREATE EXTENSION tsm_system_time;CREATE SCHEMA fast_access_schema;CREATE VIEW tablename AS SELECT * FROM data_schema TABLESAMPLE system_time(5000); --5 secsSET search_path = 'fast_access_schema, data_schema';
So, the application can use the new table without changing the SQL. Be careful, as some answers can change when you're accessing fewer rows (for ...