Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthrough文档为 Changes部分索引文档
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~5 minutes Change: Other Merge Risk: 🔵 Low · up to Users may encounter failed DDL when following the current documentation; correct the limitation list before merging. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: pingcap/docs-cn/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Advanced
Run ID: cfc296cc-d8f8-405d-8d5e-12327f14f6f0
📒 Files selected for processing (1)
sql-statements/sql-statement-add-index.md
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.
| - 部分索引的 `WHERE` 子句支持基本比较运算符(`=`、`!=`、`<`、`<=`、`>`、`>=`)、`IS NULL`、`IS NOT NULL` 和包含常量值的 `IN` 谓词。 | ||
| - 谓词中的列和常量值必须具有相同的数据类型。 | ||
| - 谓词只能引用同一表中的列。 | ||
| - 不能在表达式索引上创建部分索引。 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '220,242p' sql-statements/sql-statement-add-index.md
rg -n "partial index|PartialIndex|WHERE.*Expression|generated column|partition" . --glob '!node_modules' --glob '!vendor' | head -200Repository: pingcap/docs-cn
Length of output: 26995
🏁 Script executed:
python3 - <<'PY'
import json
import urllib.request
for ref in ("v8.5.7", "v9.0.0"):
url = f"https://api.github.com/repos/pingcap/tidb/git/trees/{ref}?recursive=1"
req = urllib.request.Request(url, headers={"User-Agent": "review-inspection"})
with urllib.request.urlopen(req) as r:
data = json.load(r)
print(f"## {ref}")
for item in data.get("tree", []):
path = item.get("path", "")
if any(term in path.lower() for term in ("partial", "index_test", "ddl/index")):
print(path)
PYRepository: pingcap/docs-cn
Length of output: 2439
🏁 Script executed:
set -eu
for ref in v8.5.7 v9.0.0; do
echo "## $ref: pkg/ddl/index.go"
curl -skL "https://raw.githubusercontent.com/pingcap/tidb/$ref/pkg/ddl/index.go" |
nl -ba | grep -i -E -C 8 'partial|generated|partition|predicate' | head -240
echo "## $ref: candidate test paths"
curl -skL "https://api.github.com/repos/pingcap/tidb/git/trees/$ref?recursive=1" |
grep -oE '"path": "[^"]+"' |
grep -i -E 'partial|ddl/.+index|index.+test' | head -100
doneRepository: pingcap/docs-cn
Length of output: 15444
🏁 Script executed:
set -eu
for ref in v8.5.7 v9.0.0; do
echo "## ref status: $ref"
curl -skL -o /tmp/tidb-ref-check -w 'HTTP %{http_code} bytes %{size_download}\n' "https://raw.githubusercontent.com/pingcap/tidb/$ref/pkg/ddl/index.go"
echo "## focused test: $ref"
curl -skL -o /tmp/tidb-partial-test -w 'HTTP %{http_code} bytes %{size_download}\n' "https://raw.githubusercontent.com/pingcap/tidb/$ref/tests/integrationtest/t/planner/core/casetest/index/partialindex.test"
if [ -s /tmp/tidb-partial-test ]; then
nl -ba /tmp/tidb-partial-test | sed -n '1,260p'
fi
echo "## focused result: $ref"
curl -skL -o /tmp/tidb-partial-result -w 'HTTP %{http_code} bytes %{size_download}\n' "https://raw.githubusercontent.com/pingcap/tidb/$ref/tests/integrationtest/r/planner/core/casetest/index/partialindex.result"
if [ -s /tmp/tidb-partial-result ]; then
nl -ba /tmp/tidb-partial-result | sed -n '1,320p'
fi
done
echo "## v8.5.7 source candidates"
for path in pkg/ddl/ddl_api.go pkg/ddl/index.go pkg/ddl/index_modify_test.go pkg/ddl/index_change_test.go; do
echo "### $path"
curl -skL "https://raw.githubusercontent.com/pingcap/tidb/v8.5.7/$path" |
nl -ba | grep -i -E -C 10 'partial|condition|generated|partition' | head -300
doneRepository: pingcap/docs-cn
Length of output: 37204
🏁 Script executed:
set -eu
rm -rf /tmp/tidb-v857-src
mkdir -p /tmp/tidb-v857-src
curl -skL "https://codeload.github.com/pingcap/tidb/tar.gz/refs/tags/v8.5.7" |
tar -xz -C /tmp/tidb-v857-src --strip-components=1
echo "## v8.5.7 condition implementation"
rg -n -C 12 'CheckAndBuildIndexConditionString|ConditionExprString|ErrUnsupportedAddPartialIndex|HasCondition' /tmp/tidb-v857-src/pkg /tmp/tidb-v857-src/tests/integrationtest/t /tmp/tidb-v857-src/tests/integrationtest/r | head -500
echo "## v8.5.7 partial-related tests"
rg -n -i -C 8 'partial index|partialindex|where .* (and|or|in)|generated.*where|partition.*where|where .*generated' /tmp/tidb-v857-src/pkg /tmp/tidb-v857-src/tests/integrationtest/t /tmp/tidb-v857-src/tests/integrationtest/r | head -500
echo "## candidate v9 refs"
curl -skL "https://api.github.com/repos/pingcap/tidb/git/matching-refs/heads/release-9" | grep -oE '"ref": "[^"]+"' | head -20 || true
curl -skL "https://api.github.com/repos/pingcap/tidb/git/matching-refs/tags/v9" | grep -oE '"ref": "[^"]+"' | head -40 || true
for ref in release-9.0 release-9.0.0 release-9; do
code=$(curl -skL -o /tmp/tidb-v9-index -w '%{http_code}' "https://raw.githubusercontent.com/pingcap/tidb/$ref/pkg/ddl/index.go")
echo "$ref HTTP $code bytes $(wc -c </tmp/tidb-v9-index)"
doneRepository: pingcap/docs-cn
Length of output: 41871
🏁 Script executed:
set -eu
echo "## validator locations"
rg -l 'CheckAndBuildIndexConditionString' /tmp/tidb-v857-src/pkg /tmp/tidb-v857-src/tests | head -30
echo "## validator definition and callers"
rg -n -C 35 'func CheckAndBuildIndexConditionString|CheckAndBuildIndexConditionString\(' /tmp/tidb-v857-src/pkg/ddl /tmp/tidb-v857-src/pkg | head -260
echo "## direct partial-index DDL tests"
rg -n -C 12 -i 'create table .*where|add .*index .*where|partial index|unsupported.*partial|where .* in \(|where .* and .*|where .* or .*' \
/tmp/tidb-v857-src/tests/integrationtest/t/ddl \
/tmp/tidb-v857-src/tests/integrationtest/t/planner/core/casetest/index \
/tmp/tidb-v857-src/pkg/ddl \
/tmp/tidb-v857-src/pkg/planner | head -400Repository: pingcap/docs-cn
Length of output: 41947
🏁 Script executed:
set -eu
nl -ba /tmp/tidb-v857-src/pkg/ddl/index.go | sed -n '3769,3945p'Repository: pingcap/docs-cn
Length of output: 9538
🏁 Script executed:
set -eu
nl -ba /tmp/tidb-v857-src/pkg/ddl/index.go | sed -n '3940,3995p'
echo "## v9 stable/tag refs matching 9.0.0"
curl -skL "https://api.github.com/repos/pingcap/tidb/git/refs?ref=tags/v9.0.0" | head -80Repository: pingcap/docs-cn
Length of output: 6504
🏁 Script executed:
set -eu
echo "## v8.5.7 expression/partial interaction"
rg -n -i -C 10 'partial.*(expression|functional)|(?:expression|functional).*partial|HasCondition\(\).*Hidden|Hidden.*HasCondition' \
/tmp/tidb-v857-src/pkg/ddl /tmp/tidb-v857-src/pkg/table /tmp/tidb-v857-src/tests/integrationtest/t | head -300
echo "## v8.5.7 index construction around expression columns"
rg -n -C 18 'func buildIndexColumns|func BuildIndexInfo|GeneratedExprString|IndexPartSpecification.*Expr' \
/tmp/tidb-v857-src/pkg/ddl/index.go | head -420
echo "## v9 beta validator comparison"
for ref in v9.0.0-beta.2 release-9.0-beta.2 master; do
echo "### $ref"
curl -skL "https://raw.githubusercontent.com/pingcap/tidb/$ref/pkg/ddl/index.go" |
grep -n -E -A95 -B5 'func CheckAndBuildIndexConditionString|func checkIndexCondition' | head -220
doneRepository: pingcap/docs-cn
Length of output: 15760
🏁 Script executed:
set -eu
echo "## add-index expression/partial guards"
rg -n -C 18 'hiddenCols|Condition.*hidden|hidden.*Condition|ExpressionIndex|expression index|functional index' \
/tmp/tidb-v857-src/pkg/ddl/executor.go /tmp/tidb-v857-src/pkg/ddl/index.go /tmp/tidb-v857-src/pkg/ddl | head -500
echo "## partial-index DDL examples involving expression index"
rg -n -i -C 8 'where[[:space:]].*(\(\(|generated)|\(\(.*\)\).*where|where.*\(\(' \
/tmp/tidb-v857-src/tests /tmp/tidb-v857-src/pkg/ddl | head -300Repository: pingcap/docs-cn
Length of output: 41951
🌐 Web query:
TiDB v9.0.0 partial index CheckAndBuildIndexConditionString pkg/ddl/index.go
💡 Result:
<source_evidence>
Citations:
- 1: https://docs.pingcap.com/tidb/stable/sql-statement-create-index/
- 2: https://github.com/pingcap/docs/blob/master/sql-statements/sql-statement-create-index.md
- 3: GitHub pull request 62759 in pingcap/tidb (link omitted to avoid creating a cross-reference)
- 4: GitHub issue 70281 in pingcap/tidb (link omitted to avoid creating a cross-reference)
- 5: GitHub pull request 62762 in pingcap/tidb (link omitted to avoid creating a cross-reference)
更正部分索引谓词限制。
实现仅支持单个简单谓词。IN 以及使用 AND 或 OR 组合的条件均不受支持。类型检查允许兼容类型,不要求完全相同。生成列和分区表不支持部分索引。
可直接应用的替换内容
-- 部分索引的 `WHERE` 子句支持基本比较运算符(`=`、`!=`、`<`、`<=`、`>`、`>=`)、`IS NULL`、`IS NOT NULL` 和包含常量值的 `IN` 谓词。
-- 谓词中的列和常量值必须具有相同的数据类型。
-- 谓词只能引用同一表中的列。
-- 不能在表达式索引上创建部分索引。
+- 部分索引的 `WHERE` 子句仅支持单个简单谓词:基本比较运算符(`=`、`!=`、`<`、`<=`、`>`、`>=`)、`IS NULL` 或 `IS NOT NULL`。不支持 `IN`,也不支持使用 `AND` 或 `OR` 组合多个条件。
+- 比较运算符两侧的列和字面量必须具有兼容的数据类型,不要求类型完全相同。
+- 谓词只能引用同一表中的可见、非生成列。分区表不支持部分索引。📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - 部分索引的 `WHERE` 子句支持基本比较运算符(`=`、`!=`、`<`、`<=`、`>`、`>=`)、`IS NULL`、`IS NOT NULL` 和包含常量值的 `IN` 谓词。 | |
| - 谓词中的列和常量值必须具有相同的数据类型。 | |
| - 谓词只能引用同一表中的列。 | |
| - 不能在表达式索引上创建部分索引。 | |
| - 部分索引的 `WHERE` 子句仅支持单个简单谓词:基本比较运算符(`=`、`!=`、`<`、`<=`、`>`、`>=`)、`IS NULL` 或 `IS NOT NULL`。不支持 `IN`,也不支持使用 `AND` 或 `OR` 组合多个条件。 | |
| - 比较运算符两侧的列和字面量必须具有兼容的数据类型,不要求类型完全相同。 | |
| - 谓词只能引用同一表中的可见、非生成列。分区表不支持部分索引。 |
What is changed, added, or deleted? (Required)
Document partial-index syntax, scenarios,
ALTER TABLE ... ADD INDEXexamples, predicate behavior, and limitations on theADD INDEXreference page.Which TiDB version(s) do your changes apply to? (Required)
Tips for choosing the affected version(s):
By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.
For details, see tips for choosing the affected versions (in Chinese).
What is the related PR or file link(s)?
AI agent involvement
Do your changes match any of the following descriptions?
Summary by CodeRabbit
ADD INDEX语法新增WHERE Expression选项,支持创建部分索引。