@@ -5708,6 +5708,100 @@ public function testCreateIndexOnNonExistentColumn(): void {
5708
5708
$ this ->assertQuery ( 'CREATE INDEX idx_value ON t (val) ' );
5709
5709
}
5710
5710
5711
+ public function testCreateComplexIndex (): void {
5712
+ $ this ->assertQuery (
5713
+ 'CREATE TABLE t (
5714
+ id INT PRIMARY KEY,
5715
+ name TEXT,
5716
+ score INT,
5717
+ created_at DATETIME
5718
+ ) '
5719
+ );
5720
+
5721
+ $ this ->assertQuery (
5722
+ 'CREATE UNIQUE INDEX idx_complex
5723
+ ON t (score ASC, name(16) DESC, created_at DESC)
5724
+ USING BTREE
5725
+ COMMENT "Test comment"
5726
+ ALGORITHM INPLACE
5727
+ LOCK SHARED '
5728
+ );
5729
+
5730
+ // Verify that the index was saved in the information schema.
5731
+ $ result = $ this ->assertQuery ( 'SHOW CREATE TABLE t ' );
5732
+ $ this ->assertCount ( 1 , $ result );
5733
+ $ this ->assertEquals (
5734
+ implode (
5735
+ "\n" ,
5736
+ array (
5737
+ 'CREATE TABLE `t` ( ' ,
5738
+ ' `id` int NOT NULL, ' ,
5739
+ ' `name` text DEFAULT NULL, ' ,
5740
+ ' `score` int DEFAULT NULL, ' ,
5741
+ ' `created_at` datetime DEFAULT NULL, ' ,
5742
+ ' PRIMARY KEY (`id`), ' ,
5743
+ " UNIQUE KEY `idx_complex` (`score`, `name`(16) DESC, `created_at` DESC) COMMENT 'Test comment' " ,
5744
+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
5745
+ )
5746
+ ),
5747
+ $ result [0 ]->{'Create Table ' }
5748
+ );
5749
+
5750
+ // Verify that the index exists in the SQLite database.
5751
+ $ result = $ this ->engine
5752
+ ->execute_sqlite_query ( "SELECT * FROM pragma_index_list('t') WHERE origin != 'pk' " )
5753
+ ->fetchAll ( PDO ::FETCH_ASSOC );
5754
+ $ this ->assertCount ( 1 , $ result );
5755
+ $ this ->assertSame (
5756
+ array (
5757
+ 'seq ' => '0 ' ,
5758
+ 'name ' => 't__idx_complex ' ,
5759
+ 'unique ' => '1 ' ,
5760
+ 'origin ' => 'c ' ,
5761
+ 'partial ' => '0 ' ,
5762
+ ),
5763
+ $ result [0 ]
5764
+ );
5765
+
5766
+ $ result = $ this ->engine
5767
+ ->execute_sqlite_query ( "SELECT * FROM pragma_index_xinfo('t__idx_complex') WHERE cid != -1 " )
5768
+ ->fetchAll ( PDO ::FETCH_ASSOC );
5769
+ $ this ->assertCount ( 3 , $ result );
5770
+ $ this ->assertEquals (
5771
+ array (
5772
+ 'seqno ' => '0 ' ,
5773
+ 'cid ' => '2 ' ,
5774
+ 'name ' => 'score ' ,
5775
+ 'desc ' => '0 ' ,
5776
+ 'coll ' => 'BINARY ' ,
5777
+ 'key ' => '1 ' ,
5778
+ ),
5779
+ $ result [0 ]
5780
+ );
5781
+ $ this ->assertEquals (
5782
+ array (
5783
+ 'seqno ' => '1 ' ,
5784
+ 'cid ' => '1 ' ,
5785
+ 'name ' => 'name ' ,
5786
+ 'desc ' => '1 ' ,
5787
+ 'coll ' => 'NOCASE ' ,
5788
+ 'key ' => '1 ' ,
5789
+ ),
5790
+ $ result [1 ]
5791
+ );
5792
+ $ this ->assertEquals (
5793
+ array (
5794
+ 'seqno ' => '2 ' ,
5795
+ 'cid ' => '3 ' ,
5796
+ 'name ' => 'created_at ' ,
5797
+ 'desc ' => '1 ' ,
5798
+ 'coll ' => 'NOCASE ' ,
5799
+ 'key ' => '1 ' ,
5800
+ ),
5801
+ $ result [2 ]
5802
+ );
5803
+ }
5804
+
5711
5805
public function testDropIndex (): void {
5712
5806
$ this ->assertQuery ( 'CREATE TABLE t (id INT PRIMARY KEY, val_unique INT UNIQUE, val_index INT) ' );
5713
5807
$ this ->assertQuery ( 'CREATE INDEX idx_val_index ON t (val_index) ' );
0 commit comments