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

parser: unexpected unknown 1 in where clause error #45898

Closed
qw4990 opened this issue Aug 8, 2023 · 3 comments · Fixed by #45903
Closed

parser: unexpected unknown 1 in where clause error #45898

qw4990 opened this issue Aug 8, 2023 · 3 comments · Fixed by #45903
Assignees
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 component/parser priority/release-blocker This issue blocks a release. Please solve it ASAP. severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@qw4990
Copy link
Contributor

qw4990 commented Aug 8, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Run the unit test below:

func TestUnknown1InWhereClause(t *testing.T) {
	store := testkit.CreateMockStore(t)
	tk := testkit.NewTestKit(t, store)
	tk.MustExec("use test")
	tk.MustExec("create table t(a varchar(32) NOT NULL primary key,b varchar(22) not null,key idx_a (a))")
	go func() {
		tkk := testkit.NewTestKit(t, store)
		tkk.MustExec(`use test`)
		for k := 0; k < 10000; k++ {
			tkk.ExecToErr("select * from xw.t1 where 1=1 a.  ")
		}
	}()
	for k := 0; k < 10000; k++ {
		tk.MustQuery(`select count(1) from t where a = 'Q13'`).Check(testkit.Rows("0"))
	}
}

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

No error.

3. What did you see instead (Required)

                Error:          Received unexpected error:
                                [planner:1054]Unknown column '1' in 'where clause'

4. What is your TiDB version? (Required)

@qw4990 qw4990 added the type/bug The issue is confirmed as a bug. label Aug 8, 2023
@qw4990
Copy link
Contributor Author

qw4990 commented Aug 8, 2023

The value 1 is parsed as a column name:
image

@qw4990
Copy link
Contributor Author

qw4990 commented Aug 8, 2023

If we allocate a new Parser each time, then it can pass this test. So it seems like Parser's status is not reset correctly when we put it back to the pool:
image

@qw4990 qw4990 changed the title planner: unexpected unknown 1 in where clause error parser: unexpected unknown 1 in where clause error Aug 8, 2023
@ti-chi-bot ti-chi-bot bot added may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Aug 8, 2023
@qw4990
Copy link
Contributor Author

qw4990 commented Aug 8, 2023

The minimum reproducible case:

func TestUnknown1InWhereClause2(t *testing.T) {
	p := parser.New()
	p.ParseSQL("a.")
	stmts, _, err := p.ParseSQL("select count(1) from t")
	require.NoError(t, err)
	var sb strings.Builder
	restoreCtx := format.NewRestoreCtx(format.DefaultRestoreFlags, &sb)
	sb.Reset()
	stmts[0].Restore(restoreCtx)
	fmt.Println("-->>> ", sb.String())
}

The result should be

SELECT COUNT(1) FROM `t`

instead of

SELECT COUNT(`1`) FROM `t`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 component/parser priority/release-blocker This issue blocks a release. Please solve it ASAP. severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants