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

Date parameters are converted to string automatically #45190

Closed
YangKeao opened this issue Jul 5, 2023 · 2 comments · Fixed by #48237
Closed

Date parameters are converted to string automatically #45190

YangKeao opened this issue Jul 5, 2023 · 2 comments · Fixed by #48237
Assignees
Labels
severity/minor sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@YangKeao
Copy link
Member

YangKeao commented Jul 5, 2023

TiDB handles the date parameters as string, which is not expected. TiDB should construct a data, but not string for these parameters. See:

		case mysql.TypeDate, mysql.TypeTimestamp, mysql.TypeDatetime:
			if len(paramValues) < (pos + 1) {
				err = mysql.ErrMalformPacket
				return
			}
			// See https://dev.mysql.com/doc/internals/en/binary-protocol-value.html
			// for more details.
			length := paramValues[pos]
			pos++
			switch length {
			case 0:
				tmp = types.ZeroDatetimeStr
			case 4:
				pos, tmp = binaryDate(pos, paramValues)
			case 7:
				pos, tmp = binaryDateTime(pos, paramValues)
			case 11:
				pos, tmp = binaryTimestamp(pos, paramValues)
			case 13:
				pos, tmp = binaryTimestampWithTZ(pos, paramValues)
			default:
				err = mysql.ErrMalformPacket
				return
			}
			args[i] = types.NewDatum(tmp) // FIXME: After check works!!!!!!
			continue
@YangKeao YangKeao added type/bug The issue is confirmed as a bug. severity/minor labels Jul 5, 2023
@jebter jebter added the sig/execution SIG execution label Jul 7, 2023
@YangKeao
Copy link
Member Author

This bugs turns to be quite complicated, especially about warn handling.

The warnings are reset during statement execution, after parsing parameters, so we cannot add warnings during the parsing of parameters 🤦. Another difficult part is that different statements can have different behaviors for warnings (related with TruncateAsWarning and something, see ResetContextOfStmt...), so we should parse the parameters after parsing the statement, which needs a big refractor.

This bug doesn't affect too much, because most of the time we don't care about the type of an argument, and it can be implicitly converted in most cases. The only problem comes into my mind is about the JSON. string and datetime have different json_type.

@YangKeao
Copy link
Member Author

YangKeao commented Aug 24, 2023

Oops, it actually brings more problem if the user converts it to another type. For example:

SELECT CAST(? AS SIGNED)

If the ? is a time: 2001-10-20 10:10:59.500000, convert a datetime to signed will give 20011020101100LL, but convert the string to signed will give 2001. That's why test_temporal_param case in mysql_client_test failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/minor sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants