USE_RANGE_CACHE and NO_RANGE_CACHE are a pair of statement-level hints for the query optimizer, controlling whether a single SQL statement uses Range Cache (range statistics cache) when it estimates the number of rows for a range scan.range_stat_enable_cache. Beyond this global switch, you can temporarily adjust the behavior for a single SQL statement using the following two hints:USE_RANGE_CACHE: Forces Range Cache to be enabled for this statement, even if the global switch range_stat_enable_cache is OFF.NO_RANGE_CACHE: Forces Range Cache to be disabled for this statement, even if the global switch range_stat_enable_cache is ON.USE_RANGE_CACHE and NO_RANGE_CACHE are parameterless hints that apply to the entire statement and do not accept parameters such as table names, index names, or query block names./*+ USE_RANGE_CACHE *//*+ NO_RANGE_CACHE */
SELECT, UPDATE, or DELETE in the statement. This is supported for SELECT, UPDATE, and DELETE statements.USE_RANGE_CACHE and NO_RANGE_CACHE (or specifying the same Hint repeatedly) in the same SQL statement triggers a conflict alarm ER_WARN_CONFLICTING_HINT, and the system uses the first-occurring Hint.USE_RANGE_CACHE takes effect only under the following conditions. Otherwise, even if the Hint is specified, Range Cache is neither created nor used:range_stat_allowed_maximum_table_size.NO_RANGE_CACHE is not subject to the storage engine restrictions mentioned above and can disable the Range Cache estimation path for any SQL statement.USE_RANGE_CACHE and NO_RANGE_CACHE to control the Range Cache behavior for a single SQL statement in scenarios with large table data volumes, and verifies the cache usage through information_schema.RANGE_CACHE.CREATE TABLE range_cache_demo (id INT NOT NULL,f1 INT DEFAULT NULL,f2 INT DEFAULT NULL,f3 INT DEFAULT NULL,PRIMARY KEY (id),KEY idx_f1 (f1),KEY idx_f2 (f2),KEY idx_f3 (f3, f2)) ENGINE = ROCKSDB DEFAULT CHARSET = utf8mb4;
NO_RANGE_CACHE to disable Range Cacherange_stat_enable_cache = ON:SELECT /*+ NO_RANGE_CACHE */ COUNT(1)FROM range_cache_demoWHERE f1 = 10;
UPDATE and DELETE statements are also supported:BEGIN;UPDATE /*+ NO_RANGE_CACHE */ range_cache_demoSET f1 = 1WHERE f1 = 10;ROLLBACK;
USE_RANGE_CACHE to forcibly enable Range CacheSET GLOBAL range_stat_enable_cache = OFF;SELECT /*+ USE_RANGE_CACHE */ COUNT(1)FROM range_cache_demoWHERE f1 = 10;SET GLOBAL range_stat_enable_cache = ON;
optimizer_trace to view the details of Hint taking effectSET optimizer_trace = 'enabled=on';SET range_stat_enable_trace_cache = ON;SELECT /*+ USE_RANGE_CACHE */ COUNT(1)FROM range_cache_demoWHERE f1 = 10;SELECT * FROM information_schema.optimizer_trace\\G
optimizer_trace output, you can view the estimation details of Range Cache to confirm whether the Hint is adopted and the specific estimated number of rows.USE_RANGE_CACHE and NO_RANGE_CACHE only affect the cost calculation path during the row count estimation phase of a Range scan. They do not change the actual data scan operators, nor do they bypass normal execution processes such as permission checks and transaction visibility.range_stat_allowed_maximum_table_size), USE_RANGE_CACHE is automatically disabled. The system then falls back to the default estimation path without causing execution errors.Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan