vitess icon indicating copy to clipboard operation
vitess copied to clipboard

Bug Report: VTExplain should throw an error on non-existing column names

Open quinox opened this issue 2 years ago • 1 comments

Overview of the Issue

VTExplain currently does not throw an error when you feed it a query with a WHERE filter on a non-existing column. This caused me some confusion because I mistyped my column name and the output showed Vitess would query all shards whereas I expected it to only ask 1 specific shard. The actual output should have told me the column name can't be used since it doesn't exist.

It does not matter whether the keyspace is sharded or not. A sharded keyspace:

vitess@0e5c9c29b9ad /v/local> vtexplain --vschema-file blaat.json  --schema-file blabla.sql --output-mode text --sql "SELECT * from customer WHERE this_column_doesnt_exist = 1" 
----------------------------------------------------------------------
SELECT * from customer WHERE this_column_doesnt_exist = 1

1 customer/-80: select * from customer where this_column_doesnt_exist = 1 limit 10001
1 customer/80-: select * from customer where this_column_doesnt_exist = 1 limit 10001

A non-sharded keyspace:

vitess@0e5c9c29b9ad /v/local> vtexplain --vschema-file blaat.json  --schema-file blabla.sql --output-mode text --sql "SELECT * from product WHERE this_column_doesnt_exist = 1" --planner-version Gen4
----------------------------------------------------------------------
SELECT * from product WHERE this_column_doesnt_exist = 1

1 commerce/-: select * from product where this_column_doesnt_exist = 1 limit 10001

It does explode as expected when I use a non-existing table name:

vitess@0e5c9c29b9ad /v/local> vtexplain --vschema-file blaat.json  --schema-file blabla.sql --output-mode text --sql "SELECT * from this_table_doesnt_exist WHERE id = 1" --planner-version V3
ERROR: logging before flag.Parse: E0803 11:51:12.104183   11508 syslogger.go:149] can't connect to syslog
ERROR: vtexplain execute error in 'SELECT * from this_table_doesnt_exist WHERE id = 1': table this_table_doesnt_exist not found

Reproduction Steps

  • Construct a vtexplain call that is legit with a simple query
  • Modify the query by adding a non-existing column to the WHERE clause
  • Observe vtexplain trying to explain how it will run the query, whereas it should have told you check your SQL because the column doesn't exist

Binary Version

I'm using the provided Docker environment. 

vitess@0e5c9c29b9ad /v/local> $ vtexplain --version
ERROR: logging before flag.Parse: E0803 12:02:57.952974   11686 syslogger.go:149] can't connect to syslog
Version: 15.0.0-SNAPSHOT (Git revision ab0ddd072599f6517406f16dff97e98e72f50cb5 branch 'main') built on Wed Aug  3 09:14:18 UTC 2022 by vitess@ac495f2676f5 using go1.18.4 linux/amd64


### Operating System and Environment details

```sh
Your Docker environment.

Log Fragments

No response

quinox avatar Aug 03 '22 12:08 quinox

cc @vitessio/query-serving

deepthi avatar Aug 05 '22 23:08 deepthi

@quinox Are you using an authoritative column list in your Vschema. The docs on this can be found here - https://vitess.io/docs/15.0/user-guides/vschema-guide/advanced-vschema/#authoritative-list.

TL;DR - If you only specify a list of columns without marking them authoritative, then vtgate and vtexplain assume that there might be more columns which aren't present in the list. So any unknown columns are still planned and we rely on MySQL to fail these queries if the column doesn't exist. If you mark the column list authoritative, then vtgate knows there are no more columns and will fail such queries.

GuptaManan100 avatar Jan 23 '23 07:01 GuptaManan100