@@ -141,35 +141,37 @@ public function getSubPartitions(): array
141141 */
142142 public static function getPartitions (string $ db , string $ table ): array
143143 {
144- if (self ::havePartitioning ()) {
145- $ dbi = DatabaseInterface::getInstance ();
146- $ result = $ dbi ->fetchResultSimple (
147- 'SELECT * FROM `information_schema`.`PARTITIONS` '
148- . ' WHERE `TABLE_SCHEMA` = ' . $ dbi ->quoteString ($ db )
149- . ' AND `TABLE_NAME` = ' . $ dbi ->quoteString ($ table ),
150- );
151- if ($ result !== []) {
152- $ partitionMap = [];
153- foreach ($ result as $ row ) {
154- if (empty ($ row ['PARTITION_NAME ' ])) {
155- continue ;
156- }
144+ if (! self ::havePartitioning ()) {
145+ return [];
146+ }
157147
158- $ partition = $ partitionMap [$ row ['PARTITION_NAME ' ]] ?? new Partition ($ row );
159- $ partitionMap [$ row ['PARTITION_NAME ' ]] = $ partition ;
148+ $ dbi = DatabaseInterface::getInstance ();
149+ $ result = $ dbi ->fetchResultSimple (
150+ 'SELECT * FROM `information_schema`.`PARTITIONS` '
151+ . ' WHERE `TABLE_SCHEMA` = ' . $ dbi ->quoteString ($ db )
152+ . ' AND `TABLE_NAME` = ' . $ dbi ->quoteString ($ table ),
153+ );
154+ if ($ result === []) {
155+ return [];
156+ }
160157
161- if (empty ($ row ['SUBPARTITION_NAME ' ])) {
162- continue ;
163- }
158+ $ partitionMap = [];
159+ foreach ($ result as $ row ) {
160+ $ partitionName = $ row ['PARTITION_NAME ' ] ?? '' ;
161+ if ($ partitionName === '' ) {
162+ continue ;
163+ }
164164
165- $ partition ->addSubPartition (new SubPartition ($ row ));
166- }
165+ $ partitionMap [$ partitionName ] ??= new Partition ($ row );
167166
168- return array_values ($ partitionMap );
167+ if (empty ($ row ['SUBPARTITION_NAME ' ])) {
168+ continue ;
169169 }
170+
171+ $ partitionMap [$ partitionName ]->addSubPartition (new SubPartition ($ row ));
170172 }
171173
172- return [] ;
174+ return array_values ( $ partitionMap ) ;
173175 }
174176
175177 /**
0 commit comments