3 declare(strict_types
=1);
12 /** @var string The column name */
15 /** @var int The column sequence number in the index, starting with 1. */
16 private $seqInIndex = 1;
19 * @var string How the column is sorted in the index. "A" (Ascending) or
22 private $collation = null;
25 * The number of indexed characters if the column is only partly indexed,
26 * NULL if the entire column is indexed.
30 private $subPart = null;
33 * Contains YES if the column may contain NULL.
34 * If not, the column contains NO.
41 * An estimate of the number of unique values in the index. This is updated
42 * by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on
43 * statistics stored as integers, so the value is not necessarily exact even
44 * for small tables. The higher the cardinality, the greater the chance that
45 * MySQL uses the index when doing joins.
49 private $cardinality = null;
52 * @param array $params an array containing the parameters of the index column
54 public function __construct(array $params = [])
60 * Sets parameters of the index column
62 * @param array $params an array containing the parameters of the index column
66 public function set(array $params)
68 if (isset($params['Column_name'])) {
69 $this->name
= $params['Column_name'];
71 if (isset($params['Seq_in_index'])) {
72 $this->seqInIndex
= $params['Seq_in_index'];
74 if (isset($params['Collation'])) {
75 $this->collation
= $params['Collation'];
77 if (isset($params['Cardinality'])) {
78 $this->cardinality
= $params['Cardinality'];
80 if (isset($params['Sub_part'])) {
81 $this->subPart
= $params['Sub_part'];
83 if (! isset($params['Null'])) {
87 $this->null = $params['Null'];
91 * Returns the column name
93 * @return string column name
95 public function getName()
101 * Return the column collation
103 * @return string column collation
105 public function getCollation()
107 return $this->collation
;
111 * Returns the cardinality of the column
113 * @return int cardinality of the column
115 public function getCardinality()
117 return $this->cardinality
;
121 * Returns whether the column is nullable
123 * @param bool $as_text whether to returned the string representation
125 * @return string nullability of the column. True/false or Yes/No depending
126 * on the value of the $as_text parameter
128 public function getNull($as_text = false): string
131 if (! $this->null ||
$this->null === 'NO') {
142 * Returns the sequence number of the column in the index
144 * @return int sequence number of the column in the index
146 public function getSeqInIndex()
148 return $this->seqInIndex
;
152 * Returns the number of indexed characters if the column is only
155 * @return int the number of indexed characters
157 public function getSubPart()
159 return $this->subPart
;
163 * Gets the properties in an array for comparison purposes
165 * @return array an array containing the properties of the index column
167 public function getCompareData()
170 'Column_name' => $this->name
,
171 'Seq_in_index' => $this->seqInIndex
,
172 'Collation' => $this->collation
,
173 'Sub_part' => $this->subPart
,
174 'Null' => $this->null,