Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update clustered index return error message:IntHandle compares to CommonHandle #29520

Closed
vivid392845427 opened this issue Nov 5, 2021 · 3 comments
Assignees
Labels
severity/critical sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.

Comments

@vivid392845427
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

config file:new_collations_enabled_on_first_bootstrap = true
CREATE TABLE `tbl_25` (
  `col_208` year(4) NOT NULL,
  PRIMARY KEY (`col_208`) CLUSTERED,
  UNIQUE KEY `idx_66` (`col_208`),
  UNIQUE KEY `idx_67` (`col_208`),
  KEY `idx_68` (`col_208`)
);
insert into tbl_25 set col_208 = '2030'; ---check

CREATE TABLE `tbl_35` (
  `col_244` year(4) NOT NULL,
  PRIMARY KEY (`col_244`) CLUSTERED,
  UNIQUE KEY `idx_206` (`col_244`),
  KEY `idx_207` (`col_244`),
  KEY `idx_208` (`col_244`),
  UNIQUE KEY `idx_209` (`col_244`),
  KEY `idx_210` (`col_244`),
  KEY `idx_211` (`col_244`),
  KEY `idx_212` (`col_244`),
  UNIQUE KEY `idx_213` (`col_244`),
  KEY `idx_214` (`col_244`)
);
replace into tbl_35 set col_244 = '1989';---check

2. What did you expect to see? (Required)

dml success;

3. What did you see instead (Required)

dml return error:
mysql> replace into tbl_35 set col_244 = '1989';
ERROR 1105 (HY000): IntHandle compares to CommonHandle

tidb log:
[2021/11/05 08:53:35.505 +00:00] [ERROR] [conn.go:920] ["connection running loop panic"] [conn=72139] [lastSQL="replace into tbl_35 set col_244 = '1989'"] [err="IntHandle compares to CommonHandle"] [stack="goroutine 81567985 [running]:\ngithub.com/pingcap/tidb/server.(*clientConn).Run.func1(0x4041f90, 0xc0ed3d20c0, 0xc09d518000)\n\t/go/src/github.com/pingcap/tidb/server/conn.go:918 +0xf5\npanic(0x35f7c40, 0x3fb1010)\n\t/usr/local/go/src/runtime/panic.go:965 +0x1b9\ngithub.com/pingcap/tidb/executor.(*ExecStmt).Exec.func1(0xc0940108f0, 0xc09cddcb00, 0xc09cddcae0)\n\t/go/src/github.com/pingcap/tidb/executor/adapter.go:334 +0x4d4\npanic(0x35f7c40, 0x3fb1010)\n\t/usr/local/go/src/runtime/panic.go:965 +0x1b9\ngithub.com/pingcap/tidb/kv.IntHandle.Compare(0x7c5, 0x4070ea8, 0xc0ed3fc600, 0xa77c3294a257672f)\n\t/go/src/github.com/pingcap/tidb/kv/key.go:188 +0xb7\ngithub.com/pingcap/tidb/table/tables.checkHandleConsistency(0xc00d776023, 0x14, 0x14, 0x1, 0xc015db0000, 0x6, 0x1000, 0x0, 0xc063bbd000, 0x9, ...)\n\t/go/src/github.com/pingcap/tidb/table/tables/mutation_checker.go:139 +0x229\ngithub.com/pingcap/tidb/table/tables.CheckDataConsistency(0x4084e50, 0xc000cdfe10, 0xc060fa6600, 0xc0d276c240, 0xc0cd20e6e0, 0x1, 0x1, 0x0, 0x0, 0x0, ...)\n\t/go/src/github.com/pingcap/tidb/table/tables/mutation_checker.go:96 +0x34e\ngithub.com/pingcap/tidb/table/tables.(*TableCommon).AddRecord(0xc0d276c240, 0x4089378, 0xc000cdfe00, 0xc0cd20e6e0, 0x1, 0x1, 0xc0cbe8e070, 0x1, 0x1, 0x4070ea8, ...)\n\t/go/src/github.com/pingcap/tidb/table/tables/tables.go:845 +0x1d90\ngithub.com/pingcap/tidb/executor.(*InsertValues).addRecordWithAutoIDHint(0xc0c6632680, 0x4041f90, 0xc0ed3e72f0, 0xc0cd20e6e0, 0x1, 0x1, 0x0, 0x1, 0xc0ed3e74a0)\n\t/go/src/github.com/pingcap/tidb/executor/insert_common.go:1136 +0x304\ngithub.com/pingcap/tidb/executor.(*InsertValues).addRecord(...)\n\t/go/src/github.com/pingcap/tidb/executor/insert_common.go:1125\ngithub.com/pingcap/tidb/executor.(*ReplaceExec).replaceRow(0xc098380510, 0x4041f90, 0xc0ed3e72f0, 0xc0cd20e6e0, 0x1, 0x1, 0xc0ed3e74a0, 0xc027d12420, 0x3, 0x4, ...)\n\t/go/src/github.com/pingcap/tidb/executor/replace.go:161 +0x1d4\ngithub.com/pingcap/tidb/executor.(*ReplaceExec).exec(0xc098380510, 0x4041f90, 0xc0ed3e72f0, 0xc063a726d8, 0x1, 0x1, 0x0, 0x0)\n\t/go/src/github.com/pingcap/tidb/executor/replace.go:242 +0x4de\ngithub.com/pingcap/tidb/executor.insertRows(0x4041f90, 0xc0ed3e72f0, 0x401bf10, 0xc098380510, 0x0, 0x368010662cb00)\n\t/go/src/github.com/pingcap/tidb/executor/insert_common.go:278 +0x392\ngithub.com/pingcap/tidb/executor.(*ReplaceExec).Next(0xc098380510, 0x4041f90, 0xc0ed3e72f0, 0xc0cd20e690, 0x0, 0xc09cddc710)\n\t/go/src/github.com/pingcap/tidb/executor/replace.go:257 +0x73\ngithub.com/pingcap/tidb/executor.Next(0x4041f90, 0xc0ed3e72f0, 0x4047258, 0xc098380510, 0xc0cd20e690, 0x0, 0x0)\n\t/go/src/github.com/pingcap/tidb/executor/executor.go:286 +0x2de\ngithub.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor(0xc0940108f0, 0x4041f90, 0xc0ed3e72f0, 0x4047258, 0xc098380510, 0x0, 0x0, 0x0, 0x0)\n\t/go/src/github.com/pingcap/tidb/executor/adapter.go:581 +0x33c\ngithub.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelay(0xc0940108f0, 0x4041f90, 0xc0ed3e72f0, 0x4047258, 0xc098380510, 0x5bb4200, 0x4041f01, 0x0, 0x0, 0x0, ...)\n\t/go/src/github.com/pingcap/tidb/executor/adapter.go:462 +0x1e5\ngithub.com/pingcap/tidb/executor.(*ExecStmt).Exec(0xc0940108f0, 0x4041f90, 0xc0ed3e72f0, 0x0, 0x0, 0x0, 0x0)\n\t/go/src/github.com/pingcap/tidb/executor/adapter.go:411 +0x707\ngithub.com/pingcap/tidb/session.runStmt(0x4041f90, 0xc0ed3e6ed0, 0xc000cdfe00, 0x405aeb0, 0xc0940108f0, 0x0, 0x0, 0x0, 0x0)\n\t/go/src/github.com/pingcap/tidb/session/session.go:1674 +0x37f\ngithub.com/pingcap/tidb/session.(*session).ExecuteStmt(0xc000cdfe00, 0x4041f90, 0xc0ed3e6ed0, 0x405f678, 0xc094010410, 0x0, 0x0, 0x0, 0x0)\n\t/go/src/github.com/pingcap/tidb/session/session.go:1568 +0xab1\ngithub.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt(0xc0ed3e6540, 0x4041f90, 0xc0ed3e6ed0, 0x405f678, 0xc094010410, 0xc03a2ed840, 0x4041f90, 0xc0ed3e6ed0, 0x2d)\n\t/go/src/github.com/pingcap/tidb/server/driver_tidb.go:219 +0x6b\ngithub.com/pingcap/tidb/server.(*clientConn).handleStmt(0xc09d518000, 0x4041ee8, 0xc0ed3e6ed0, 0x405f678, 0xc094010410, 0x5be72a8, 0x0, 0x0, 0x1, 0x0, ...)\n\t/go/src/github.com/pingcap/tidb/server"]

4. What is your TiDB version? (Required)

Release Version: v5.3.0-alpha-36-g2f8f4d60b
Edition: Community
Git Commit Hash: 2f8f4d60b62f60fd66cdc9f4d3ec0e283e8e8c0f
Git Branch: ft-data-inconsistency
UTC Build Time: 2021-10-28 02:19:44
GoVersion: go1.16.9
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@vivid392845427 vivid392845427 added type/bug The issue is confirmed as a bug. sig/transaction SIG:Transaction severity/critical labels Nov 5, 2021
@ekexium
Copy link
Contributor

ekexium commented Nov 8, 2021

The year type is stored as an Int64 in the datum. The row is encoded as a common handle, but decoded as an int handle.
It seems a little weird to me. I don't know if it's intentional.
To work around it we can simply ignore the case when handle types mismatch.

A test case to reproduce it:

func TestYearTypeCommonHandle(t *testing.T) {
	tblInfo := buildTableInfo(t, "CREATE TABLE `tbl_25` (`col_208` int, PRIMARY KEY (`col_208`) CLUSTERED, "+
		"KEY `idx_68` (`col_208`));")
	store, clean := testkit.CreateMockStore(t)
	defer clean()
	txn, err := store.Begin()
	require.NoError(t, err)
	mockCtx := mock.NewContext()
	sc := mockCtx.GetSessionVars().StmtCtx

	var nonUniqueIdx table.Index
	for _, idxInfo := range tblInfo.Indices {
		idx := tables.NewIndex(tblInfo.ID, tblInfo, idxInfo)
		if !idxInfo.Primary {
			nonUniqueIdx = idx
		}
	}

	data := []types.Datum{types.NewIntDatum(2020)}
	encodedHandle, err := codec.EncodeKey(sc, nil, data...)
	require.NoError(t, err)
	commonHandle, err := kv.NewCommonHandle(encodedHandle)
	require.NoError(t, err)

	key, _, err := nonUniqueIdx.GenIndexKey(sc, data, commonHandle, nil)
	_, err = nonUniqueIdx.Create(mockCtx, txn, data, commonHandle, nil)
	require.NoError(t, err)
	val, err := txn.Get(context.Background(), key)
	require.NoError(t, err)
	handle, err := tablecodec.DecodeIndexHandle(key, val, 1)
	require.NoError(t, err)
	require.True(t, handle.IsInt())
}

ekexium added a commit to ekexium/tidb that referenced this issue Nov 9, 2021
Signed-off-by: ekexium <ekexium@gmail.com>
ekexium added a commit that referenced this issue Nov 11, 2021
Signed-off-by: ekexium <ekexium@gmail.com>
@ekexium
Copy link
Contributor

ekexium commented Nov 11, 2021

Closed by #29600

@ekexium ekexium closed this as completed Nov 11, 2021
@github-actions
Copy link

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

@jebter jebter added the affects-5.3 This bug affects 5.3.x versions. label Nov 30, 2021
@ekexium ekexium removed the affects-5.3 This bug affects 5.3.x versions. label Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/critical sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants