| 270 | } |
| 271 | |
| 272 | uint get_join_table_result_set(TABLE_LIST *table) { |
| 273 | MYSQL *con = mysql_init(NULL); |
| 274 | if (con == NULL) { |
| 275 | finish_with_error(con); |
| 276 | } |
| 277 | |
| 278 | if (mysql_real_connect(con, options.host, options.username, |
| 279 | options.password, options.dbname, options.port, NULL, 0) == NULL) { |
| 280 | finish_with_error(con); |
| 281 | } |
| 282 | |
| 283 | mysql_query(con, "set names utf8"); |
| 284 | |
| 285 | uint result_set_count; |
| 286 | GString *cardinality_sql = g_string_new(NULL); |
| 287 | if (table->index_field_head != NULL) { |
| 288 | if (table->index_field_head->index_field->field_name->table_name |
| 289 | == NULL) { |
| 290 | g_string_sprintf(cardinality_sql, |
| 291 | "explain select * from %s where %s", table->table_name, |
| 292 | table->index_field_head->index_field->field_print); |
| 293 | } else { |
| 294 | g_string_sprintf(cardinality_sql, |
| 295 | "explain select * from %s as %s where %s", |
| 296 | table->table_name, |
| 297 | table->index_field_head->index_field->field_name->table_name, |
| 298 | table->index_field_head->index_field->field_print); |
| 299 | } |
| 300 | } else { |
| 301 | g_string_sprintf(cardinality_sql, "explain select * from %s", |
| 302 | table->table_name); |
| 303 | } |
| 304 | |
| 305 | print_sql(cardinality_sql->str); |
| 306 | |
| 307 | if (mysql_query(con, cardinality_sql->str)) { |
| 308 | finish_with_error(con); |
| 309 | } |
| 310 | |
| 311 | MYSQL_RES *result = mysql_store_result(con); |
| 312 | if (result == NULL) { |
| 313 | finish_with_error(con); |
| 314 | } |
| 315 | |
| 316 | int num_fields = mysql_num_fields(result); |
| 317 | |
| 318 | MYSQL_ROW row; |
| 319 | |
| 320 | if ((row = mysql_fetch_row(result))) { |
| 321 | result_set_count = atoi(row[EXPLAIN_ROWS]); |
| 322 | } |
| 323 | g_string_free(cardinality_sql, TRUE); |
| 324 | mysql_free_result(result); |
| 325 | mysql_close(con); |
| 326 | return result_set_count; |
| 327 | } |
| 328 | |
| 329 | void final_table_drived() { |
no test coverage detected