burrito-brothers / shiba

Catch bad SQL queries before they cause problems in production
https://shiba-sql.com
Other
292 stars 14 forks source link

Handle table aliases for MySQL queries #30

Open kianris opened 5 years ago

kianris commented 5 years ago

I've been testing out Shiba with queries in a log file for a non-Ruby project. It seems like some queries are working with aliases but not others. Is this because there is no SQL parsing performed within Shiba yet?

Alternatively I could list the aliases as part of the /*shiba*/ metadata with each query.

eac commented 5 years ago

I'll take a look at this. Can you include a sample from your log file of a query or two that aren't working?

kianris commented 5 years ago

In MySQL:

create table Shiba(id bigint not null auto_increment, primary key(id), value varchar(255));

Explain and review without alias select * from Shiba

select * from Shiba:-2 ()
 * Table Scan: mysql reads 100% (1000) of the of the rows in **Shiba**, skipping any indexes.
 * Estimated query time: 0.01s

Explain and review with alias select * from Shiba s

<No output>
eac commented 5 years ago

Fix is almost ready, I'll try to get a release out in the next few days.

eac commented 5 years ago

I've released support for capitalized table names and aliases for simple queries on mysql. More complex queries featuring joins aren't supported.