tbl_partition_definition.inc.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Table partition definition
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Core;
  9. if (!isset($partitionDetails)) {
  10. $partitionDetails = array();
  11. // Extract some partitioning and subpartitioning parameters from the request
  12. $partitionParams = array(
  13. 'partition_by', 'partition_expr',
  14. 'subpartition_by', 'subpartition_expr',
  15. );
  16. foreach ($partitionParams as $partitionParam) {
  17. $partitionDetails[$partitionParam] = isset($_POST[$partitionParam])
  18. ? $_POST[$partitionParam] : '';
  19. }
  20. if (Core::isValid($_POST['partition_count'], 'numeric')) {
  21. // MySQL's limit is 8192, so do not allow more
  22. $partition_count = min(intval($_POST['partition_count']), 8192);
  23. } else {
  24. $partition_count = 0;
  25. }
  26. $partitionDetails['partition_count']
  27. = ($partition_count === 0) ? '' : $partition_count;
  28. if (Core::isValid($_POST['subpartition_count'], 'numeric')) {
  29. // MySQL's limit is 8192, so do not allow more
  30. $subpartition_count = min(intval($_POST['subpartition_count']), 8192);
  31. } else {
  32. $subpartition_count = 0;
  33. }
  34. $partitionDetails['subpartition_count']
  35. = ($subpartition_count === 0) ? '' : $subpartition_count;
  36. // Only LIST and RANGE type parameters allow subpartitioning
  37. $partitionDetails['can_have_subpartitions'] = $partition_count > 1
  38. && isset($_POST['partition_by'])
  39. && ($_POST['partition_by'] == 'RANGE'
  40. || $_POST['partition_by'] == 'RANGE COLUMNS'
  41. || $_POST['partition_by'] == 'LIST'
  42. || $_POST['partition_by'] == 'LIST COLUMNS');
  43. // Values are specified only for LIST and RANGE type partitions
  44. $partitionDetails['value_enabled'] = isset($_POST['partition_by'])
  45. && ($_POST['partition_by'] == 'RANGE'
  46. || $_POST['partition_by'] == 'RANGE COLUMNS'
  47. || $_POST['partition_by'] == 'LIST'
  48. || $_POST['partition_by'] == 'LIST COLUMNS');
  49. // Has partitions
  50. if ($partition_count > 1) {
  51. $partitions = isset($_POST['partitions'])
  52. ? $_POST['partitions']
  53. : array();
  54. // Remove details of the additional partitions
  55. // when number of partitions have been reduced
  56. array_splice($partitions, $partition_count);
  57. for ($i = 0; $i < $partition_count; $i++) {
  58. if (! isset($partitions[$i])) { // Newly added partition
  59. $partitions[$i] = array(
  60. 'name' => 'p' . $i,
  61. 'value_type' => '',
  62. 'value' => '',
  63. 'engine' => '',
  64. 'comment' => '',
  65. 'data_directory' => '',
  66. 'index_directory' => '',
  67. 'max_rows' => '',
  68. 'min_rows' => '',
  69. 'tablespace' => '',
  70. 'node_group' => '',
  71. );
  72. }
  73. $partition =& $partitions[$i];
  74. $partition['prefix'] = 'partitions[' . $i . ']';
  75. // Changing from HASH/KEY to RANGE/LIST
  76. if (! isset($partition['value_type'])) {
  77. $partition['value_type'] = '';
  78. $partition['value'] = '';
  79. }
  80. if (! isset($partition['engine'])) { // When removing subpartitioning
  81. $partition['engine'] = '';
  82. $partition['comment'] = '';
  83. $partition['data_directory'] = '';
  84. $partition['index_directory'] = '';
  85. $partition['max_rows'] = '';
  86. $partition['min_rows'] = '';
  87. $partition['tablespace'] = '';
  88. $partition['node_group'] = '';
  89. }
  90. if ($subpartition_count > 1
  91. && $partitionDetails['can_have_subpartitions'] == true
  92. ) { // Has subpartitions
  93. $partition['subpartition_count'] = $subpartition_count;
  94. if (! isset($partition['subpartitions'])) {
  95. $partition['subpartitions'] = array();
  96. }
  97. $subpartitions =& $partition['subpartitions'];
  98. // Remove details of the additional subpartitions
  99. // when number of subpartitions have been reduced
  100. array_splice($subpartitions, $subpartition_count);
  101. for ($j = 0; $j < $subpartition_count; $j++) {
  102. if (! isset($subpartitions[$j])) { // Newly added subpartition
  103. $subpartitions[$j] = array(
  104. 'name' => $partition['name'] . '_s' . $j,
  105. 'engine' => '',
  106. 'comment' => '',
  107. 'data_directory' => '',
  108. 'index_directory' => '',
  109. 'max_rows' => '',
  110. 'min_rows' => '',
  111. 'tablespace' => '',
  112. 'node_group' => '',
  113. );
  114. }
  115. $subpartition =& $subpartitions[$j];
  116. $subpartition['prefix'] = 'partitions[' . $i . ']'
  117. . '[subpartitions][' . $j . ']';
  118. }
  119. } else { // No subpartitions
  120. unset($partition['subpartitions']);
  121. unset($partition['subpartition_count']);
  122. }
  123. }
  124. $partitionDetails['partitions'] = $partitions;
  125. }
  126. }