The explicit specification of an index in a list query is actually slower, in what situations will it degrade to a full table scan?

📅 October 12, 2026 👁️ 13

The explicit index specification in list query is actually slower, the problem lies in the case when the hint points to an index that no longer matches the current query conditions. Hardcoding an index is equivalent to making the optimizer give up the right to choose the path based on statistical information: when the combination of conditions changes or the data distribution changes, the forced index may only have the usage of scanning back to the table, which is much more costly than the original covered index or range scan; when the conditions are completely invalid, this path degrades to a full table scan.

What does the optimizer choose the index based on?

Query the index to be used by the optimizer when no hint is provided, referring to the index structure, the distribution of field values, and the estimated number of rows hit. It does not pursue the 'most relevant index', but rather the 'total cost path'——including how many pages to read, whether to retrieve the rest of the fields row by row, and whether the result needs to be sorted again. An index that matches only by field name is not necessarily better than another index that includes sorted fields when the number of hit rows is large. Such judgments depend on statistical information and hints written statically in the code are not visible.

Who decides after the prompt is written in stone

The scope of the prompt has three different strengths of expression, all of which exclude other candidates. Once specified, the optimizer no longer compares costs and will not automatically change selections due to inappropriate indices.The risk point lies in the fact that the prompt is often added during a slow query: at that time, it indeed solved the problem, but the data volume, field distribution, and query conditions will continue to change, while the prompt will not change accordingly.PbootCMS in the V3.2.26 update log provides the fix for this type of issue, the query of the list tag degraded to full table scan due to index hints, and the new installed libraries are unifiedly changed to build indexes based on the title field - both sides are changed together, indicating that the cause is that the index structure is too tightly bound with the hints.

Trigger condition The result brought by the prompt Phenomenon Method of processing
Query added new filtering conditions The specified index cannot be used for the new condition, scan first then filter Response time increases exponentially Remove the prompt first, let the optimizer choose by itself
The distribution of field values changes Estimated number of rows hit increases, the cost of returning to the table increases Fast for cold data, slow for hot data Review the order of index fields
The sorting field is inconsistent with the index Extra sorting is needed, the index is only used as a filter 明显变慢 when performing large pagination Rebuild index by combining sorting and filtering
Write the condition as a function or implicit conversion Index column fails, directly degrade Execution plan shows full table scan Rewrite the condition, don't cover it with hints

Which combination of conditions is most prone to degradation

The fourth type is the most common. **This type performs function operations or comparisons with inconsistent types on index columns, and the values on the columns must be converted to match, the index cannot be used to locate.The second type is a prefix wildcard fuzzy match, which cannot take advantage of the ordered structure when the pattern starts with a wildcard. The third type is filtering and sorting belonging to different indexes, the optimizer needs to choose between one index scan with sorting and another index scan without sorting, while the prompt will compress the choice space into one.The fourth type is a small field index on a wide table: when the number of matching rows is large, it is more expensive to retrieve the remaining fields row by row than to scan the entire table in order, which is exactly the situation where the forced index is most likely to fail.

The order of location and verification

The order should be to first look at the execution plan before making configuration changes, not relying on intuition or prompts. **Step 1: Take the current execution plan, confirm the actual used index, estimated row count, and whether there is additional sorting;Step two: remove the prompt and run it once again, compare the cost of the two runs; in many cases, the optimizer's chosen path is more optimal; Step three: check if the index column order covers the combination of filtering and sorting, and rebuild if necessary instead of adding hints;Observe the performance after the data volume changes in the fourth step, and change the writing that only applies to the current scale back to condition-driven. The efficiency of list queries has a direct impact on page loading speed, the official statement for AnQiCMS is that it has a significant improvement compared to traditional PHP programs, and can handle about 5 million PV on a single machine, these conclusions are about overall architectural capabilities, and still need to use execution plans to verify specific queries.AnQiCMS's data layer builds queries through GORM, index design should be considered together with field combinations and query conditions. The practice of hardcoding index names is more likely to become disconnected from the actual structure in this abstract layer.

Common questions

Q: After adding hints to the slow query, it is indeed faster, why should it be removed? A: That optimization solved the data distribution at that time. Keeping the hint will prevent the subsequent conditions from changing automatically, and manual review is required to avoid accidents.

How can you determine if it has degraded into a full table scan?\nAnswer: Look at the scan type and estimated row count in the execution plan, as well as whether it is accompanied by additional sorting; just looking at the response time will miss the differences caused by scale changes.

What does it mean to build a field index uniformly in the new library?\nAnswer: It means that the maintenance party tends to decouple the index structure from the query writing style, avoiding the tight binding of hints with the actual index.

Related articles

Why does the program overwrite the entire site configuration file when saving settings, and why does it overwrite the rules I added myself?

When saving settings, the program overwrites the directory-level configuration file, taking away the manually added rules along with it, because these files are only one copy, generated in full by the program according to its own template. The same program PbootCMS has fixed this issue in the update record of V3.2.26: When Apache turns on pseudo-static, it misjudges the environment, causing the configuration file under the site directory to be overwritten every time it is saved. The approach is to separate the rules managed by the program from the rules added by operations and maintain them in two places, backup before modification, and compare item by item after modification.

2026-10-12

What is the situation when the login credentials are partitioned by the top-level site when embedded by other sites?

Login credentials with partition attributes are stored separately by the top-level site: one is read when the same address is accessed directly, and another is read when the page is embedded by other sites, and they do not share. The official document states that this attribute indicates that credentials should be stored using partitioned storage, and it must be set at the same time as the security mark, and it is recommended to bind the credentials to the host with a hostname prefix name instead of a registrable domain. If the site assumes that the login state is globally shared, it will not be read in the embedded scenario.

2026-10-12

In the front-end monitoring, the loading time of cross-domain images is all zero, which response header should be added

The loading time of cross-domain images is read as zero in the front-end monitoring, the missing is the timing pass response header. The official document defines: this header specifies which sources are allowed to see the attribute values obtained through the resource timing interface, otherwise these values will be reported as zero due to cross-domain restrictions. The value can be a wildcard to release all sources, or a comma-separated list of sources. It only affects timing readings and does not change the access permissions of the resources, so adding this header solves the attribution problem, not the access problem.

2026-10-12

The intermediate response code for pre-loading resources on the first screen, why is it only issued in multi-path multiplexing protocols in most cases?

The 103 intermediate response used for pre-loading resources on the first screen is a prompt issued by the server before it organizes the final page, allowing the client to pre-connect or pre-load resources. The official documentation suggests that for compatibility and security reasons, it should only be sent in HTTP protocol version 2 or higher, as most browsers only support it under these conditions. The reason is that under old protocols, the boundary handling between intermediate responses and final responses is inconsistent, which is easy to confuse with the content of waiting responses.

2026-10-12

Why should the database script in the online upgrade be arranged in version order, and what should be done if it fails halfway

The database script for the online upgrade must be executed strictly in the order of version numbers, as each script is based on the premise that 'the previous one has been completed': the new field has not been created, and the next one will fail when writing values. Skipping intermediate versions during cross-version upgrade will leave the table structure halfway. If the script fails halfway, the safe approach is to stop immediately and leave a log, rather than ignoring the error and continuing to run the remaining scripts, otherwise the problem will be covered by the subsequent scripts. Make a backup of data and static files before the upgrade, and check each section after the upgrade.

2026-10-12

Why would the entry be lost and keep getting bigger when writing the intercept list to a file?

Write the login intercept list to a single file, and it is easy to lose entries under concurrent writing: two requests read the same content at the same time, append it separately, and write it back, the one written later covers the previous one, and the addresses blocked are thus removed from the list. A file without a capacity limit will continue to grow, and the time for reading and parsing will also increase; irregular malformed entries will cause parsing errors directly, leading to the overall failure of the list. The list is just a layer, and the server still needs to have independent verification and captcha links.

2026-10-12

The cause of the core announcement is writing the built-in third-party library, in addition to waiting for the patch, the station also needs to look at which part

The cause is written in the core announcement of the built-in third-party library, the vulnerability is not in the code written by the station itself, but it is distributed with the core, so it cannot be avoided by changing your own template or business code, and can only follow the core version. When following up, read three sections: the upper and lower bounds of the affected range determine whether your version is hit, the fixed version determines which version to upgrade to, and the rating and exploitation conditions determine the priority of scheduling. Taking the Drupal announcement SA-CORE-2026-013 as an example, the affected range spans three branches, and the fixes are in the latest version of each branch.

2026-10-12

Under the same repair date, there are two announcements with different reporting dates hanging, and follow-up should be arranged according to which time.

Under the same fix date, there are two announcements with different reporting dates. The follow-up is arranged according to the fix date, not the reporting date. The fix date represents the actual release of the patch with which version, which is the day you can start working; the reporting date only indicates the time when the vulnerability was notified, used to estimate how long the exposure window is; the announcement release date is the time when the public information is released, usually not earlier than the fix date. Taking two core announcements of the Joomla Security Center as an example, the reporting dates are August 19th and August 2nd, respectively, and the fix dates are both September 25th, and the affected range and upgrade target version are also consistent.

2026-10-12