| 2157 | */ |
| 2158 | |
| 2159 | bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db, |
| 2160 | const LEX_CSTRING *table_name, uint flags, |
| 2161 | const char *table_path) |
| 2162 | { |
| 2163 | char path[FN_REFLEN + 1]; |
| 2164 | const size_t pathmax = sizeof(path) - 1 - reg_ext_length; |
| 2165 | int error= 0; |
| 2166 | DBUG_ENTER("quick_rm_table"); |
| 2167 | |
| 2168 | DBUG_ASSERT(flags & (QRMT_FRM | QRMT_PAR | QRMT_HANDLER)); |
| 2169 | size_t path_length= table_path ? |
| 2170 | (strxnmov(path, pathmax, table_path, NullS) - path) : |
| 2171 | build_table_filename(path, pathmax, db->str, table_name->str, "", flags); |
| 2172 | if (flags & QRMT_PAR) |
| 2173 | { |
| 2174 | /* |
| 2175 | Normally .par is removed by QRMT_HANDLER. Caller may want to remove it |
| 2176 | explicitly along with .FRM in some cases. |
| 2177 | */ |
| 2178 | DBUG_ASSERT(flags & QRMT_FRM); |
| 2179 | DBUG_ASSERT(!(flags & QRMT_HANDLER)); |
| 2180 | handler *file= get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base); |
| 2181 | if (!file) |
| 2182 | DBUG_RETURN(true); |
| 2183 | (void) file->ha_create_partitioning_metadata(path, NULL, CHF_DELETE_FLAG, |
| 2184 | true); |
| 2185 | delete file; |
| 2186 | } |
| 2187 | if (flags & QRMT_HANDLER) |
| 2188 | { |
| 2189 | uint keys, total_keys; |
| 2190 | int hlindex_error= get_hlindex_keys_by_open(thd, db, table_name, path, |
| 2191 | &keys, &total_keys); |
| 2192 | error|= ha_delete_table(thd, base, path, db, table_name, 0) > 0; |
| 2193 | if (!hlindex_error) |
| 2194 | { |
| 2195 | char idx_path[FN_REFLEN + 1]; |
| 2196 | char *idx_path_end= strmov(idx_path, path); |
| 2197 | for (uint i= keys; i < total_keys; i++) |
| 2198 | { |
| 2199 | my_snprintf(idx_path_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); |
| 2200 | if (ha_delete_table(thd, base, idx_path, db, table_name, 0)) |
| 2201 | error= 1; |
| 2202 | } |
| 2203 | } |
| 2204 | else |
| 2205 | error= 1; |
| 2206 | } |
| 2207 | |
| 2208 | if (flags & QRMT_FRM) |
| 2209 | { |
| 2210 | memcpy(path + path_length, reg_ext, reg_ext_length + 1); |
| 2211 | if (mysql_file_delete(key_file_frm, path, MYF(0))) |
| 2212 | error= 1; /* purecov: inspected */ |
| 2213 | } |
| 2214 | |
| 2215 | if (likely(error == 0)) |
| 2216 | { |
no test coverage detected