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

sql: internal error: unexpected separator '-' for field Hour as type date #36146

Closed
maddyblue opened this issue Mar 26, 2019 · 8 comments · Fixed by #36545
Closed

sql: internal error: unexpected separator '-' for field Hour as type date #36146

maddyblue opened this issue Mar 26, 2019 · 8 comments · Fixed by #36545
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sqlsmith

Comments

@maddyblue
Copy link
Contributor

WITH
	with_23483 (col_189248, col_189249)
		AS (
			SELECT
				*
			FROM
				(
					VALUES
						(e'\x06%I':::STRING, '73 years 939 days 15:38:41.183869':::INTERVAL),
						(
							experimental_strftime('1976-12-16':::DATE::DATE, e'z$Hy\f\x1eFi':::STRING::STRING)::STRING,
							'-46 years -4 mons -648 days -15:23:49.276911':::INTERVAL
						),
						('e':::STRING, '-56 years -8 mons -806 days -24:35:24.285986':::INTERVAL),
						(
							substring(rtrim((e'{"b": [[[], 1.4707758355371465], false, {"K<\\"3": null, "c": null, "t_ukOG(n04": []}, {"foo": []}], "foobar": [[], false]}':::JSONB::JSONB#>>ARRAY[e'$\x1a9y\x0ek>%':::STRING]::STRING[])::STRING)::STRING::STRING, e'm$(8:\x7f':::STRING::STRING)::STRING,
							'-41 years -9 mons -60 days -12:31:28.705106':::INTERVAL
						),
						('Iy':::STRING, '-56 years -10 mons -382 days -01:40:09.609735':::INTERVAL)
				)
					AS tab_39008 (col_189248, col_189249)
		)
SELECT
	with_23483.col_189248 AS col_189250,
	'2f607933-36cf-4711-8976-7568c8f63ae7':::UUID AS col_189251,
	'{"*[`LqSv": {"b": {"bar": []}}, "b": [{"foobar": [[false], {"foobar": 0.9732046466402267}, 0.6208557814767016, true]}, 2.60792012278648], "gcO)fIqTP~": [], "~Xx ($_F{+:": {"bar": 1.9330563668710494}}':::JSONB
		AS col_189252,
	false AS col_189253,
	with_23483.col_189248 AS col_189254,
	CASE
	WHEN not_like_escape(with_23483.col_189248::STRING, with_23483.col_189248::STRING, substring('0|[@:?)3':::STRING::STRING, with_23483.col_189248::STRING)::STRING::STRING)::BOOL
	THEN NULL
	ELSE (404482251864031.2750:::DECIMAL::DECIMAL // ((-8.651253944420003642E+26):::DECIMAL::DECIMAL + 347951987218551.3227:::DECIMAL::DECIMAL)::DECIMAL)
	END
		AS col_189255,
	true AS col_189256,
	B'1100011101011100000010010101111011100101010010111' AS col_189257,
	('1971-03-18':::DATE::DATE + 300866802885581286:::INT8::INT8) AS col_189258,
	age('1970-01-06 12:19:21.000284+00:00':::TIMESTAMPTZ::TIMESTAMPTZ, '1970-01-11 16:37:28.000469+00:00':::TIMESTAMPTZ::TIMESTAMPTZ)::INTERVAL
		AS col_189259
FROM
	with_23483
WHERE
	true
ORDER BY
	with_23483.col_189248;
util/timeutil/pgdate/parsing.go:155 in inputErrorf(): (XX000) internal error: '108672393952-01-22':::DATE: unexpected separator '-' for field Hour as type date
-- detail --
expr.go:83: %s | *tree.AnnotateTypeExpr
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/expr.go:83: in processExpression()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/expr.go:165: in init()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:152: in Init()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:853: in InitWithEvalCtx()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:829: in Init()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/values.go:61: in newValuesProcessor()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:998: in newProcessor()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:350: in makeProcessor()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:425: in setupProcessors()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:525: in setup()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/server.go:463: in setupFlow()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/server.go:518: in SetupLocalSyncFlow()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:241: in Run()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:840: in PlanAndRun()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1121: in execWithDistSQLEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:957: in dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:459: in execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:101: in execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1183: in run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:433: in ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:338: in func4()
E190326 06:02:06.705695 36073 sql/sqltelemetry/report.go:39  encountered internal error:
util/timeutil/pgdate/parsing.go:155 in inputErrorf(): (XX000) internal error: '108672393952-01-22':::DATE: unexpected separator '-' for field Hour as type date
-- detail --
expr.go:83: %s | *tree.AnnotateTypeExpr
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/expr.go:83: in processExpression()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/expr.go:165: in init()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:152: in Init()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:853: in InitWithEvalCtx()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:829: in Init()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/values.go:61: in newValuesProcessor()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/processors.go:998: in newProcessor()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:350: in makeProcessor()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:425: in setupProcessors()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/flow.go:525: in setup()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/server.go:463: in setupFlow()
github.com/cockroachdb/cockroach/pkg/sql/distsqlrun/server.go:518: in SetupLocalSyncFlow()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:241: in Run()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:840: in PlanAndRun()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1121: in execWithDistSQLEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:957: in dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:459: in execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:101: in execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1183: in run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:433: in ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:338: in func4()
CRASHER:
caused by: server panic: pq: internal error: '108672393952-01-22':::DATE: unexpected separator '-' for field Hour as type date
@maddyblue maddyblue added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Mar 26, 2019
@jordanlewis
Copy link
Member

@mjibson this isn't a panic as far as I can tell, right? How come the test seems to have marked it as a crasher?

@jordanlewis
Copy link
Member

Looks like the root cause is probably that we can't roundtrip weird dates properly.

root@127.0.0.1:54423/defaultdb> select '1971-03-18':::DATE::DATE + 300866802885581286:::INT8::INT8;
              ?column?
+-----------------------------------+
  108672393952-01-22 00:00:00+00:00
(1 row)


root@127.0.0.1:54423/defaultdb> select '108672393952-01-22 00:00:00+00:00'::date;
pq: unexpected separator '-' for field Hour as type date

@bobvawter by any chance do you expect this to work properly?

For the record, Postgres doesn't permit adding dates and bigints together.

But, even dates that are constructible by adding a date and an int4 can be unparsable by Cockroach:

jordan=# select '825716-07-24';
   ?column?
--------------
 825716-07-24
(1 row)

root@127.0.0.1:54485/defaultdb> select '825716-07-24';
    ?column?
+--------------+
  825716-07-24

@bobvawter, I think we should be able to roundtrip such dates since we can construct them via addition. Could you take a brief look at what's preventing this from being possible? To be honest, I don't think that fixing this is very important, but we should separately prevent this assertion error from firing as it seems to be possible in the wild. I'll take care of that part.

@maddyblue
Copy link
Contributor Author

Anything marked internal error or assertion error (i.e., things that used to be panics be we now try to catch in a defer) is treated as a crasher since it is definitely a problem.

@maddyblue
Copy link
Contributor Author

Is someone working on this?

@bobvawter
Copy link
Member

This is distinct from #35602. I'll take a look at it tomorrow.

@bobvawter bobvawter self-assigned this Apr 2, 2019
@maddyblue
Copy link
Contributor Author

maddyblue commented Apr 4, 2019

Smallest repro I could find:

WITH
    w (c) AS (VALUES (NULL), (NULL))
SELECT
    '1971-03-18'::DATE + 300866802885581286
FROM
    w
ORDER BY
    c;

@maddyblue
Copy link
Contributor Author

maddyblue commented Apr 4, 2019

Removing the ORDER BY or reducing the row count in the VALUES from 2 to 1 will not trigger this internal error. I assume this has to do with either some heuristic about this turning off the optimizer, or maybe distsql setting up some flows in some way. @jordanlewis do you happen to know? I'm just curious.

@jordanlewis
Copy link
Member

It's probably distsql roundtrip serialization. Heh, after our earlier conversation, we should add a PBT that all expressions can be roundtripped by distsql. I can't believe I didn't think of this earlier.

craig bot pushed a commit that referenced this issue Apr 5, 2019
36545: pgdate: correctly parse dates with large year parts r=mjibson a=mjibson

Fixes #36146

Release note (bug fix): Don't error when parsing dates with large years.

Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
@craig craig bot closed this as completed in #36545 Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sqlsmith
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants