dolthub / dolthub/dolt

"SELECT * FROM tbl" has incorrect schema when table has default values.

Open
#6,396 1 comment 0 reactions 0 assignees View on GitHub
analyzer bug sql
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 8h
Merged PRs (30d)
120

Description

Dolt often makes a query of the form "SELECT * from tbl" and examines the resulting schema in order to get a table schema. However, depending on specific factors, this resulting schema may be missing information about:

defaults
auto_increment
primary keys

The issue seems to be a mismatch between the Project node and the EraseProject optimization.

- Project.Schema() only considers the name, type, and nullability of the underlying table. It does not report defaultness, primary key-ness, and extra metadata like auto_increment.
- The EraseProject optimization removes Project nodes if it detects that they have no affect on the result. It does this by comparing the schema of the Project node with the schema of the underlying columns. However, this check does consider default values, but doesn't consider primary-keyness or auto_increment.

The main consequence of this mismatch is that if the underlying table has a column with a default value, then the Project node will NEVER have the same schema as the underlying table, and the Project node will never be removed from the plan tree. THEN, because Project nodes don't report the defaultnes, primary key-ness, or auto-increment, ALL of those attributes end up stripped from the final schema.

However, if the underlying table doesn't have a column with a default value, then those same values will be in the result table schema.

(Mirror of https://github.com/dolthub/go-mysql-server/issues/1753)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the SELECT * schema behavior described in the issue, then trace Project.Schema() and the EraseProject optimization. Compare the schemas used by those two components, and verify that defaults, auto_increment, and primary-key metadata remain present in the final table schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.