macbre/index-digest

Ignore views

macbre opened this issue · 1 comments

  File "/opt/wikia/index-digest/indexdigest/linters/linter_0028_data_too_old.py", line 86, in check_data_too_old
    1. * (metadata['data_size'] + metadata['index_size']) / 1024 / 1024
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
>show full tables;
+--------------------------------+------------+
| Tables_in_discussion_migration | Table_type |
+--------------------------------+------------+
| delete_ids                     | BASE TABLE |
| migrate_batch                  | BASE TABLE |
| migrated                       | VIEW       |
| site_status                    | BASE TABLE |
| to_migrate                     | VIEW       |
+--------------------------------+------------+

--

>SELECT ENGINE, TABLE_ROWS, DATA_LENGTH, INDEX_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA='discussion_migration' AND TABLE_NAME='migrated';
+--------+------------+-------------+--------------+
| ENGINE | TABLE_ROWS | DATA_LENGTH | INDEX_LENGTH |
+--------+------------+-------------+--------------+
| NULL   |       NULL |        NULL |         NULL |
+--------+------------+-------------+--------------+

Test case

mysql> CREATE TABLE t (qty INT, price INT);
mysql> INSERT INTO t VALUES(3, 50);
mysql> CREATE VIEW v AS SELECT qty, price, qty*price AS value FROM t;
mysql> SELECT * FROM v;
+------+-------+-------+
| qty  | price | value |
+------+-------+-------+
|    3 |    50 |   150 |
+------+-------+-------+

CREATE VIEW

mysql> explain select * from 0000_the_view;
+----+-------------+----------------+------------+-------+-----------------+---------+---------+------+------+----------+-------------+
| id | select_type | table          | partitions | type  | possible_keys   | key     | key_len | ref  | rows | filtered | Extra       |
+----+-------------+----------------+------------+-------+-----------------+---------+---------+------+------+----------+-------------+
|  1 | PRIMARY     | <derived2>     | NULL       | ALL   | NULL            | NULL    | NULL    | NULL |    4 |   100.00 | NULL        |
|  2 | DERIVED     | 0000_the_table | NULL       | index | PRIMARY,idx_foo | idx_foo | 50      | NULL |    4 |   100.00 | Using index |
+----+-------------+----------------+------------+-------+-----------------+---------+---------+------+------+----------+-------------+
2 rows in set, 1 warning (0,01 sec)

--

mysql> SELECT ENGINE, TABLE_ROWS, DATA_LENGTH, INDEX_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA='index_digest' AND TABLE_NAME='0000_the_view';
+--------+------------+-------------+--------------+
| ENGINE | TABLE_ROWS | DATA_LENGTH | INDEX_LENGTH |
+--------+------------+-------------+--------------+
| NULL   |       NULL |        NULL |         NULL |
+--------+------------+-------------+--------------+

--

mysql> SHOW CREATE TABLE `0000_the_view`\G
*************************** 1. row ***************************
                View: 0000_the_view
         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`index_digest`@`%` SQL SECURITY DEFINER VIEW `0000_the_view` AS select `0000_the_table`.`foo` AS `foo`,count(0) AS `cnt` from `0000_the_table` group by `0000_the_table`.`foo`
character_set_client: utf8
collation_connection: utf8_general_ci

--

mysql> select TABLE_NAME from information_schema.tables where table_schema = 'index_digest' and TABLE_TYPE = 'BASE TABLE';
+---------------------------------------+
| TABLE_NAME                            |
+---------------------------------------+
| 0000_the_table                        |
| 0000_the_table-metadata               |
| 0002_not_used_indices                 |
| 0004_id_foo                           |
...