5
5
6
6
7
7
use Vimeo \MysqlEngine \FakePdoInterface ;
8
+ use Vimeo \MysqlEngine \Query \ShowIndexQuery ;
9
+ use Vimeo \MysqlEngine \Schema \Column ;
8
10
9
11
class ShowIndexProcessor extends Processor
10
12
{
11
13
public static function process (
12
14
FakePdoInterface $ conn ,
13
- string $ table
14
- ): array
15
- {
16
- $ result = [];
17
- [$ database , $ table ] = Processor::parseTableName ($ conn , $ table );
15
+ Scope $ scope ,
16
+ ShowIndexQuery $ stmt
17
+ ): QueryResult {
18
+ [$ database , $ table ] = Processor::parseTableName ($ conn , $ stmt ->table );
18
19
$ table_definition = $ conn ->getServer ()->getTableDefinition (
19
20
$ database ,
20
21
$ table
21
22
);
23
+ $ columns = [
24
+ 'Table ' => new Column \Varchar (255 ),
25
+ 'Non_unique ' => new Column \TinyInt (true , 1 ),
26
+ 'Key_name ' => new Column \Varchar (255 ),
27
+ 'Seq_in_index ' => new Column \intColumn (true , 4 ),
28
+ 'Column_name ' => new Column \Varchar (255 ),
29
+ 'Collation ' => new Column \Char (1 ),
30
+ 'Cardinality ' => new Column \intColumn (true , 4 ),
31
+ 'Sub_part ' => new Column \intColumn (true , 4 ),
32
+ 'Packed ' => new Column \TinyInt (true , 1 ),
33
+ 'Null ' => new Column \Varchar (3 ),
34
+ 'Index_type ' => new Column \Varchar (5 ),
35
+ 'Comment ' => new Column \Varchar (255 ),
36
+ 'Index_comment ' => new Column \Varchar (255 )
37
+ ];
38
+ $ rows = [];
22
39
foreach ($ table_definition ->indexes as $ name => $ index ) {
23
40
foreach ($ index ->columns as $ i => $ column ) {
24
- $ result [] = [
41
+ $ rows [] = [
25
42
'Table ' => $ table_definition ->name ,
26
43
'Non_unique ' => $ index ->type === 'INDEX ' ? 1 : 0 ,
27
44
'Key_name ' => $ name ,
28
- 'Seq_in_index ' => $ i+ 1 ,
45
+ 'Seq_in_index ' => $ i + 1 ,
29
46
'Column_name ' => $ column ,
47
+ // Index には "direction" がない(CreateIndex の $cols にはある)ため null
48
+ 'Collation ' => null ,
30
49
/*
31
- * https://dev.mysql.com/doc/refman/5.6/ja/create-index.html
32
- * index_col_name の指定を ASC または DESC で終了させることができます。
33
- * これらのキーワードは、インデックス値の昇順または降順での格納を指定する将来の拡張のために許可されています。
34
- * 現在、これらは解析されますが、無視されます。インデックス値は、常に昇順で格納されます。
35
- */
36
- 'Collation ' => 'A ' ,
37
- /*
38
- * https://dev.mysql.com/doc/refman/5.6/ja/analyze-table.html
50
+ * https://dev.mysql.com/doc/refman/8.0/en/analyze-table.html
39
51
* ANALYZE TABLE が未実装のため null
40
52
*/
41
53
'Cardinality ' => null ,
42
- // Index には "length" がない(CreateIndex の $cols にはある)ため null
54
+ // Index には "length" がない(CreateIndex の $cols にはある)ため null
43
55
'Sub_part ' => null ,
44
56
// PACK_KEYS が未実装のため null
45
57
'Packed ' => null ,
@@ -53,6 +65,7 @@ public static function process(
53
65
];
54
66
}
55
67
}
56
- return $ result ;
68
+ $ result = self ::applyWhere ($ conn , $ scope , $ stmt ->whereClause , new QueryResult ($ rows , $ columns ));
69
+ return new QueryResult (array_merge ($ result ->rows ), $ result ->columns );
57
70
}
58
71
}
0 commit comments