GBase 8a supports views. When a view is created, every table or other view it references must exist; if one of them is dropped later, querying the view fails. The China-domestically developed GBase 8a MPP database from GBASE provides check table to verify whether a view's references are still valid.
Syntax
check table [vc.][db.]VIEW_NAME
Example
The sample below creates a view, drops the table behind it, and compares the check table output before and after:
gbase> create table a(id int);
Query OK, 0 rows affected (Elapsed: 00:00:00.07)
gbase> insert into a values(8);
Query OK, 1 row affected (Elapsed: 00:00:00.07)
gbase> select * from a;
+------+
| id |
+------+
| 8 |
+------+
1 row in set (Elapsed: 00:00:00.02)
gbase> create view v_a as select * from a;
Query OK, 0 rows affected (Elapsed: 00:00:00.06)
gbase> select * from v_a;
+------+
| id |
+------+
| 8 |
+------+
1 row in set (Elapsed: 00:00:00.02)
gbase> check table v_a;
+----------+-------+----------+----------------------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+----------+-------+----------+----------------------------------------------------------------------------------+
| test.v_a | check | Error | (GBA-02SC-1001) The query includes syntax that is not supported by the gcluster. |
| test.v_a | check | status | OK |
+----------+-------+----------+----------------------------------------------------------------------------------+
2 rows in set (Elapsed: 00:00:00.00)
gbase> drop table a;
Query OK, 0 rows affected (Elapsed: 00:00:00.06)
gbase> check table v_a;
+----------+-------+----------+----------------------------------------------------------------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+----------+-------+----------+----------------------------------------------------------------------------------------------------------------------------+
| test.v_a | check | Error | Table 'vc1.test.a' doesn't exist |
| test.v_a | check | Error | View 'test.v_a' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| test.v_a | check | error | Corrupt |
+----------+-------+----------+----------------------------------------------------------------------------------------------------------------------------+
3 rows in set (Elapsed: 00:00:00.00)
gbase>
While the table exists, check table reports 2 rows: an unsupported-syntax error from the gcluster layer plus a status of OK. Once the table is dropped, it reports 3 rows — Table 'vc1.test.a' doesn't exist, an invalid-reference error, and Corrupt.
Going forward, run check table on a gbase view when a query suddenly fails after schema changes. It separates a broken reference from a gbase database permission problem without re-creating the view.
Top comments (0)