TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Using Redundant Conditions to Unlock Indexes in MySQL

84 点作者 adoxyz将近 2 年前

5 条评论

stux将近 2 年前
As the article notes,<p>&gt; Redundant conditions are nice because they require no changes to the database [...] This makes them useful for queries that are only sometimes run or where indexes can&#x27;t be easily added to the main conditions<p>but where possible I typically prefer adding an index on the expression that the query is using (if your database supports it) since it expresses your intent more clearly. A redundant condition is more likely to get &quot;optimized away&quot; by other developers or changes in the query planner.
评论 #36232521 未加载
karmakaze将近 2 年前
The largest query I wrote was for estimating student loan repayments over a large time period. It solved a problem by running a dense 2 page query for 2 minutes in DB2 on a mainframe. The only way it ran at all was with many heuristic bounding conditions that limited the search space for the more specific conditions, as well as applying the most recent PTFs (patches) to increase query complexity limits. It wasn&#x27;t however at all maintainable so was legacy code from day one.
评论 #36234929 未加载
berkle4455将近 2 年前
&gt; In this example, we could use a range scan instead of the YEAR function to obtain the same result.<p>The range scan will miss all items with a created_at from 2023-12-31 00:00:01 to 2023-12-31 23:59:59
评论 #36230263 未加载
评论 #36231209 未加载
web3-is-a-scam将近 2 年前
Does this technique generally work with postgres as well?
评论 #36231848 未加载
评论 #36230863 未加载
deleugpn将近 2 年前
At this point, doesn&#x27;t it make more sense to just throw away the original where condition and use only the redundant condition? If it&#x27;s really redundant and makes no different to the result, why keeping the inefficient clause be useful once the new&#x2F;better clause has been added?
评论 #36234185 未加载
评论 #36230995 未加载