Report select queries with *
macbre opened this issue · 1 comments
macbre commented
select_star
When you
SELECT *
, you're often retrieving more columns from the database than your application really needs to function. This causes more data to move from the database server to the client, slowing access and increasing load on your machines, as well as taking more time to travel across the network. This is especially true when someone adds new columns to underlying tables that didn't exist and weren't needed when the original consumers coded their data access.https://github.com/jarulraj/sqlcheck/blob/master/docs/query/3001.md
-- report these
SELECT * FROM foo;
SELECT t.* FROM foo AS t;
-- false positives
SELECT 3 * 3;
SELECT count(*) FROM foo;
SELECT /* foo */ test FROM foo;
macbre commented
>>> sql_metadata.get_query_tokens('SELECT * FROM foo;')
[<DML 'SELECT' at 0x7FAFD7F6A870>, <Wildcard '*' at 0x7FAFD7F6A738>, <Keyword 'FROM' at 0x7FAFD7F6A600>, <Name 'foo' at 0x7FAFD7F6A6D0>, <Punctuation ';' at 0x7FAFD7F6AA78>]
>>> sql_metadata.get_query_tokens('SELECT t.* FROM foo;')
[<DML 'SELECT' at 0x7FAFD7F6AB48>, <Name 't' at 0x7FAFD7F6AC18>, <Punctuation '.' at 0x7FAFD7F6AC80>, <Wildcard '*' at 0x7FAFD7F6ACE8>, <Keyword 'FROM' at 0x7FAFD7F6ADB8>, <Name 'foo' at 0x7FAFD7F6AE88>, <Punctuation ';' at 0x7FAFD7F6AEF0>]
>>> sql_metadata.get_query_tokens('SELECT count(*) FROM foo;')
[<DML 'SELECT' at 0x7FAFD7EC6050>, <Name 'count' at 0x7FAFD7EC6120>, <Punctuation '(' at 0x7FAFD7EC6188>, <Wildcard '*' at 0x7FAFD7EC61F0>, <Punctuation ')' at 0x7FAFD7EC6258>, <Keyword 'FROM' at 0x7FAFD7EC6328>, <Name 'foo' at 0x7FAFD7EC63F8>, <Punctuation ';' at 0x7FAFD7EC6460>]