MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / foreign_key_prefix

Function foreign_key_prefix

sql/sql_class.cc:137–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135*/
136
137bool foreign_key_prefix(Key *a, Key *b)
138{
139 /* Ensure that 'a' is the generated key */
140 if (a->generated)
141 {
142 if (b->generated && a->columns.elements > b->columns.elements)
143 swap_variables(Key*, a, b); // Put shorter key in 'a'
144 }
145 else
146 {
147 if (!b->generated)
148 return TRUE; // No foreign key
149 swap_variables(Key*, a, b); // Put generated key in 'a'
150 }
151
152 /* Test if 'a' is a prefix of 'b' */
153 if (a->columns.elements > b->columns.elements)
154 return TRUE; // Can't be prefix
155
156 List_iterator<Key_part_spec> col_it1(a->columns);
157 List_iterator<Key_part_spec> col_it2(b->columns);
158 const Key_part_spec *col1, *col2;
159
160#ifdef ENABLE_WHEN_INNODB_CAN_HANDLE_SWAPED_FOREIGN_KEY_COLUMNS
161 while ((col1= col_it1++))
162 {
163 bool found= 0;
164 col_it2.rewind();
165 while ((col2= col_it2++))
166 {
167 if (*col1 == *col2)
168 {
169 found= TRUE;
170 break;
171 }
172 }
173 if (!found)
174 return TRUE; // Error
175 }
176 return FALSE; // Is prefix
177#else
178 while ((col1= col_it1++))
179 {
180 col2= col_it2++;
181 if (!(*col1 == *col2))
182 return TRUE;
183 }
184 return FALSE; // Is prefix
185#endif
186}
187
188
189/****************************************************************************

Callers

nothing calls this directly

Calls 1

rewindMethod · 0.45

Tested by

no test coverage detected