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

prepared statement failed to fetch rows #41918

Closed
D3Hunter opened this issue Mar 3, 2023 · 5 comments
Closed

prepared statement failed to fetch rows #41918

D3Hunter opened this issue Mar 3, 2023 · 5 comments
Assignees
Labels
affects-6.6 affects-7.0 affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@D3Hunter
Copy link
Contributor

D3Hunter commented Mar 3, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

tidb 6.2.0 is ok, for tidb6.6.0, change param type to int will ok too.

data

create table t(updated_at timestamp, phase varchar(100));
insert into t values('2023-01-03 09:37:10', 'failed');

test code, mysql driver v1.7.0

func TestQueryMySQL(t *testing.T) {
	db, err := sql.Open("mysql", "root:123456@tcp(127.0.0.1:4000)/dataflow") //?parseTime=true&loc=Asia%2FShanghai
	if err != nil {
		panic(err)
	}
	defer db.Close()
	ctx := context.Background()
	conn, err := db.Conn(ctx)
	if err != nil {
		panic(err)
	}
	defer conn.Close()
	queryAndPrint(t, conn, "select version()")
	executePsAndPrint(t, conn, "select * from t WHERE TIMESTAMPDIFF(SECOND, updated_at, UTC_TIMESTAMP()) > ?", 300.000000)
	queryAndPrint(t, conn, "select * from t WHERE TIMESTAMPDIFF(SECOND, updated_at, UTC_TIMESTAMP()) > 300.000000")
}

func queryAndPrint(t *testing.T, conn *sql.Conn, sql string) {
	fmt.Println("execute using stmt:")
	rows, err := conn.QueryContext(context.Background(), sql)
	if err != nil {
		panic(err)
	}
	defer rows.Close()
	printRows(t, rows)
}

func printRows(t *testing.T, rows *sql.Rows) {
	columns, err := rows.Columns()
	require.NoError(t, err)
	dst := make([]interface{}, len(columns))
	for i := range columns {
		dst[i] = &[]byte{}
	}
	for rows.Next() {
		err := rows.Scan(dst...)
		require.NoError(t, err)
		var s string
		for _, v := range dst {
			s += fmt.Sprintf("%v, ", string(*v.(*[]byte)))
		}
		fmt.Println("Row:", s)
	}
}

func executePsAndPrint(t *testing.T, conn *sql.Conn, sql string, args ...any) {
	fmt.Println("execute using prepared stmt:")
	ctx := context.Background()
	ps, err2 := conn.PrepareContext(ctx, sql)
	require.NoError(t, err2)
	rows, err2 := ps.QueryContext(ctx, args...)
	require.NoError(t, err2)
	defer rows.Close()
	printRows(t, rows)
}

result

=== RUN   TestQueryMySQL
execute using stmt:
Row: 5.7.25-TiDB-v6.2.0, 
execute using prepared stmt:
Row: 2023-01-03 09:37:10, failed, 
execute using stmt:
Row: 2023-01-03 09:37:10, failed, 
--- PASS: TestQueryMySQL (0.01s)
PASS

=== RUN   TestQueryMySQL
execute using stmt:
Row: 5.7.25-TiDB-v6.6.0, 
execute using prepared stmt:
execute using stmt:
Row: 2023-01-03 09:37:10, failed, 
--- PASS: TestQueryMySQL (0.01s)
PASS

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

prepared statement can get same result at normal stmt

3. What did you see instead (Required)

empty result

4. What is your TiDB version? (Required)

6.6.0

@D3Hunter D3Hunter added type/bug The issue is confirmed as a bug. affects-6.6 labels Mar 3, 2023
@D3Hunter
Copy link
Contributor Author

D3Hunter commented Mar 3, 2023

current master branch has this problem too

@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. 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 labels Mar 6, 2023
@VelocityLight VelocityLight added the affects-7.1 This bug affects the 7.1.x(LTS) versions. label Apr 20, 2023
@ti-chi-bot ti-chi-bot added the affects-7.5 This bug affects the 7.5.x(LTS) versions. label Oct 23, 2023
@ti-chi-bot ti-chi-bot added the affects-8.1 This bug affects the 8.1.x(LTS) versions. label Apr 9, 2024
@XuHuaiyu XuHuaiyu added sig/planner SIG: Planner and removed sig/execution SIG execution labels Apr 28, 2024
@qw4990 qw4990 self-assigned this Apr 29, 2024
@qw4990
Copy link
Contributor

qw4990 commented May 8, 2024

Can't reproduce this issue, this issue should have been fixed by some other PR:
image

@qw4990 qw4990 closed this as completed May 8, 2024
@D3Hunter
Copy link
Contributor Author

7.1.5 still have this issue

=== RUN   TestQueryMySQL
execute using stmt:
Row: 5.7.25-TiDB-v7.1.5, 
execute using prepared stmt:
execute using stmt:
Row: 2023-01-03 09:37:10, failed, 
--- PASS: TestQueryMySQL (0.01s)
PASS

@D3Hunter D3Hunter reopened this May 10, 2024
@qw4990
Copy link
Contributor

qw4990 commented May 14, 2024

Fixed #48413
7.1.6 Cherry pick: #53266

@fixdb
Copy link
Contributor

fixdb commented May 20, 2024

@qw4990 Can you cherry-pick to 7.5?

@qw4990 qw4990 removed the may-affects-4.0 This bug maybe affects 4.0.x versions. label May 21, 2024
@qw4990 qw4990 removed may-affects-5.1 This bug maybe affects 5.1.x versions. 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-5.0 This bug maybe affects 5.0.x versions. may-affects-6.1 may-affects-6.5 labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.6 affects-7.0 affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

7 participants