142
bool buildScemas(Session *session)
144
session->getLex()->sql_command= SQLCOM_SELECT;
145
session->getLex()->statement= new statement::Show(session);
147
std::string column_name= "Database";
148
if (session->getLex()->wild)
150
column_name.append(" (");
151
column_name.append(session->getLex()->wild->ptr());
152
column_name.append(")");
155
if (session->getLex()->current_select->where)
157
if (prepare_new_schema_table(session, session->getLex(), "SCHEMAS"))
162
if (prepare_new_schema_table(session, session->getLex(), "SHOW_SCHEMAS"))
166
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
167
my_field->is_autogenerated_name= false;
168
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
170
if (session->add_item_to_list(my_field))
173
if (session->add_order_to_list(my_field, true))
179
bool buildTables(Session *session, const char *ident)
181
session->getLex()->sql_command= SQLCOM_SELECT;
183
drizzled::statement::Show *select= new statement::Show(session);
184
session->getLex()->statement= select;
186
std::string column_name= "Tables_in_";
188
util::string::const_shared_ptr schema(session->schema());
191
identifier::Schema identifier(ident);
192
column_name.append(ident);
193
session->getLex()->select_lex.db= const_cast<char *>(ident);
194
if (not plugin::StorageEngine::doesSchemaExist(identifier))
196
my_error(ER_BAD_DB_ERROR, identifier);
198
select->setShowPredicate(ident, "");
200
else if (schema and not schema->empty())
202
column_name.append(*schema);
203
select->setShowPredicate(*schema, "");
207
my_error(ER_NO_DB_ERROR, MYF(0));
212
if (session->getLex()->wild)
214
column_name.append(" (");
215
column_name.append(session->getLex()->wild->ptr());
216
column_name.append(")");
219
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLES"))
222
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME");
223
my_field->is_autogenerated_name= false;
224
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
226
if (session->add_item_to_list(my_field))
229
if (session->add_order_to_list(my_field, true))
235
bool buildTemporaryTables(Session *session)
237
session->getLex()->sql_command= SQLCOM_SELECT;
239
session->getLex()->statement= new statement::Show(session);
242
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TEMPORARY_TABLES"))
245
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
248
(session->getLex()->current_select->with_wild)++;
253
bool buildTableStatus(Session *session, const char *ident)
255
session->getLex()->sql_command= SQLCOM_SELECT;
256
drizzled::statement::Show *select= new statement::Show(session);
257
session->getLex()->statement= select;
259
std::string column_name= "Tables_in_";
261
util::string::const_shared_ptr schema(session->schema());
264
session->getLex()->select_lex.db= const_cast<char *>(ident);
266
identifier::Schema identifier(ident);
267
if (not plugin::StorageEngine::doesSchemaExist(identifier))
269
my_error(ER_BAD_DB_ERROR, identifier);
272
select->setShowPredicate(ident, "");
276
select->setShowPredicate(*schema, "");
280
my_error(ER_NO_DB_ERROR, MYF(0));
284
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLE_STATUS"))
287
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->
292
(session->getLex()->current_select->with_wild)++;
297
bool buildEngineStatus(Session *session, LEX_STRING)
299
session->getLex()->sql_command= SQLCOM_SELECT;
300
drizzled::statement::Show *select= new statement::Show(session);
301
session->getLex()->statement= select;
303
my_error(ER_USE_DATA_DICTIONARY);
307
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident)
309
session->getLex()->sql_command= SQLCOM_SELECT;
311
drizzled::statement::Show *select= new statement::Show(session);
312
session->getLex()->statement= select;
314
util::string::const_shared_ptr schema(session->schema());
317
select->setShowPredicate(schema_ident, table_ident->table.str);
319
else if (table_ident->db.str)
321
select->setShowPredicate(table_ident->db.str, table_ident->table.str);
325
select->setShowPredicate(*schema, table_ident->table.str);
329
my_error(ER_NO_DB_ERROR, MYF(0));
334
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
335
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
337
my_error(ER_TABLE_UNKNOWN, identifier);
341
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
344
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
347
(session->getLex()->current_select->with_wild)++;
352
void buildSelectWarning(Session *session)
354
(void) create_select_for_variable(session, "warning_count");
355
session->getLex()->statement= new statement::Show(session);
358
void buildSelectError(Session *session)
360
(void) create_select_for_variable(session, "error_count");
361
session->getLex()->statement= new statement::Show(session);
364
void buildWarnings(Session *session)
366
session->getLex()->statement= new statement::ShowWarnings(session);
369
void buildErrors(Session *session)
371
session->getLex()->statement= new statement::ShowErrors(session);
374
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
376
session->getLex()->sql_command= SQLCOM_SELECT;
377
drizzled::statement::Show *select= new statement::Show(session);
378
session->getLex()->statement= select;
380
util::string::const_shared_ptr schema(session->schema());
383
select->setShowPredicate(schema_ident, table_ident->table.str);
385
else if (table_ident->db.str)
387
select->setShowPredicate(table_ident->db.str, table_ident->table.str);
391
select->setShowPredicate(*schema, table_ident->table.str);
395
my_error(ER_NO_DB_ERROR, MYF(0));
400
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
401
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
403
my_error(ER_TABLE_UNKNOWN, identifier);
407
if (prepare_new_schema_table(session, session->getLex(), "SHOW_INDEXES"))
410
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
413
(session->getLex()->current_select->with_wild)++;
418
bool buildStatus(Session *session, const drizzled::sql_var_t is_global)
420
session->getLex()->sql_command= SQLCOM_SELECT;
421
session->getLex()->statement= new statement::Show(session);
423
if (is_global == OPT_GLOBAL)
425
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_STATUS"))
430
if (prepare_new_schema_table(session, session->getLex(), "SESSION_STATUS"))
434
std::string key("Variable_name");
435
std::string value("Value");
437
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
438
my_field->is_autogenerated_name= false;
439
my_field->set_name(key.c_str(), key.length(), system_charset_info);
441
if (session->add_item_to_list(my_field))
444
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
445
my_field->is_autogenerated_name= false;
446
my_field->set_name(value.c_str(), value.length(), system_charset_info);
448
if (session->add_item_to_list(my_field))
454
bool buildCreateTable(Session *session, Table_ident *ident)
456
session->getLex()->sql_command= SQLCOM_SELECT;
457
statement::Show *select= new statement::Show(session);
458
session->getLex()->statement= select;
460
if (session->getLex()->statement == NULL)
463
if (prepare_new_schema_table(session, session->getLex(), "TABLE_SQL_DEFINITION"))
466
util::string::const_shared_ptr schema(session->schema());
469
select->setShowPredicate(ident->db.str, ident->table.str);
473
select->setShowPredicate(*schema, ident->table.str);
477
my_error(ER_NO_DB_ERROR, MYF(0));
481
std::string key("Table");
482
std::string value("Create Table");
484
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME");
485
my_field->is_autogenerated_name= false;
486
my_field->set_name(key.c_str(), key.length(), system_charset_info);
488
if (session->add_item_to_list(my_field))
491
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
492
my_field->is_autogenerated_name= false;
493
my_field->set_name(value.c_str(), value.length(), system_charset_info);
495
if (session->add_item_to_list(my_field))
501
bool buildProcesslist(Session *session)
503
session->getLex()->sql_command= SQLCOM_SELECT;
504
session->getLex()->statement= new statement::Show(session);
506
if (prepare_new_schema_table(session, session->getLex(), "PROCESSLIST"))
509
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
512
(session->getLex()->current_select->with_wild)++;
517
bool buildVariables(Session *session, const drizzled::sql_var_t is_global)
519
session->getLex()->sql_command= SQLCOM_SELECT;
520
session->getLex()->statement= new statement::Show(session);
522
if (is_global == OPT_GLOBAL)
524
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_VARIABLES"))
529
if (prepare_new_schema_table(session, session->getLex(), "SESSION_VARIABLES"))
533
std::string key("Variable_name");
534
std::string value("Value");
536
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
537
my_field->is_autogenerated_name= false;
538
my_field->set_name(key.c_str(), key.length(), system_charset_info);
540
if (session->add_item_to_list(my_field))
543
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
544
my_field->is_autogenerated_name= false;
545
my_field->set_name(value.c_str(), value.length(), system_charset_info);
547
if (session->add_item_to_list(my_field))
553
bool buildCreateSchema(Session *session, LEX_STRING &ident)
555
session->getLex()->sql_command= SQLCOM_SELECT;
556
drizzled::statement::Show *select= new statement::Show(session);
557
session->getLex()->statement= select;
559
if (prepare_new_schema_table(session, session->getLex(), "SCHEMA_SQL_DEFINITION"))
562
util::string::const_shared_ptr schema(session->schema());
565
select->setShowPredicate(ident.str);
569
select->setShowPredicate(*schema);
573
my_error(ER_NO_DB_ERROR, MYF(0));
577
std::string key("Database");
578
std::string value("Create Database");
580
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
581
my_field->is_autogenerated_name= false;
582
my_field->set_name(key.c_str(), key.length(), system_charset_info);
584
if (session->add_item_to_list(my_field))
587
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
588
my_field->is_autogenerated_name= false;
589
my_field->set_name(value.c_str(), value.length(), system_charset_info);
591
if (session->add_item_to_list(my_field))
597
bool buildDescribe(Session *session, Table_ident *ident)
599
session->getLex()->lock_option= TL_READ;
600
init_select(session->getLex());
601
session->getLex()->current_select->parsing_place= SELECT_LIST;
602
session->getLex()->sql_command= SQLCOM_SELECT;
603
drizzled::statement::Show *select= new statement::Show(session);
604
session->getLex()->statement= select;
605
session->getLex()->select_lex.db= 0;
607
util::string::const_shared_ptr schema(session->schema());
610
select->setShowPredicate(ident->db.str, ident->table.str);
614
select->setShowPredicate(*schema, ident->table.str);
618
my_error(ER_NO_DB_ERROR, MYF(0));
623
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str);
624
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
626
my_error(ER_TABLE_UNKNOWN, identifier);
630
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
635
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->
642
(session->getLex()->current_select->with_wild)++;
647
} /* namespace drizzled */
278
#define LIST_PROCESS_HOST_LEN 64
280
static bool get_field_default_value(Field *timestamp_field,
281
Field *field, String *def_value,
285
bool has_now_default;
288
We are using CURRENT_TIMESTAMP instead of NOW because it is
291
has_now_default= (timestamp_field == field &&
292
field->unireg_check != Field::TIMESTAMP_UN_FIELD);
294
has_default= (field->type() != DRIZZLE_TYPE_BLOB &&
295
!(field->flags & NO_DEFAULT_VALUE_FLAG) &&
296
field->unireg_check != Field::NEXT_NUMBER);
298
def_value->length(0);
302
def_value->append(STRING_WITH_LEN("CURRENT_TIMESTAMP"));
303
else if (!field->is_null())
304
{ // Not null by default
305
char tmp[MAX_FIELD_WIDTH];
306
String type(tmp, sizeof(tmp), field->charset());
307
field->val_str(&type);
311
uint32_t dummy_errors;
312
/* convert to system_charset_info == utf8 */
313
def_val.copy(type.ptr(), type.length(), field->charset(),
314
system_charset_info, &dummy_errors);
316
append_unescaped(def_value, def_val.ptr(), def_val.length());
318
def_value->append(def_val.ptr(), def_val.length());
321
def_value->append(STRING_WITH_LEN("''"));
323
else if (field->maybe_null() && quoted)
324
def_value->append(STRING_WITH_LEN("NULL")); // Null as default
332
Build a CREATE TABLE statement for a table.
336
table_list A list containing one table to write statement
338
packet Pointer to a string where statement will be
342
Currently always return 0, but might return error code in the
349
int store_create_info(TableList *table_list, String *packet, bool is_if_not_exists)
351
List<Item> field_list;
352
char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
355
String type(tmp, sizeof(tmp), system_charset_info);
356
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
358
uint32_t primary_key;
360
Table *table= table_list->table;
361
Cursor *cursor= table->cursor;
362
TableShare *share= table->s;
363
HA_CREATE_INFO create_info;
364
bool show_table_options= false;
365
my_bitmap_map *old_map;
367
table->restoreRecordAsDefault(); // Get empty record
369
if (share->tmp_table)
370
packet->append(STRING_WITH_LEN("CREATE TEMPORARY TABLE "));
372
packet->append(STRING_WITH_LEN("CREATE TABLE "));
373
if (is_if_not_exists)
374
packet->append(STRING_WITH_LEN("IF NOT EXISTS "));
375
alias= share->table_name.str;
377
packet->append_identifier(alias, strlen(alias));
378
packet->append(STRING_WITH_LEN(" (\n"));
380
We need this to get default values from the table
381
We have to restore the read_set if we are called from insert in case
382
of row based replication.
384
old_map= table->use_all_columns(table->read_set);
386
for (ptr=table->field ; (field= *ptr); ptr++)
388
uint32_t flags = field->flags;
390
if (ptr != table->field)
391
packet->append(STRING_WITH_LEN(",\n"));
393
packet->append(STRING_WITH_LEN(" "));
394
packet->append_identifier(field->field_name, strlen(field->field_name));
396
// check for surprises from the previous call to Field::sql_type()
397
if (type.ptr() != tmp)
398
type.set(tmp, sizeof(tmp), system_charset_info);
400
type.set_charset(system_charset_info);
402
field->sql_type(type);
403
packet->append(type.ptr(), type.length(), system_charset_info);
405
if (field->has_charset())
407
if (field->charset() != share->table_charset)
409
packet->append(STRING_WITH_LEN(" CHARACTER SET "));
410
packet->append(field->charset()->csname);
414
For string types dump collation name only if
415
collation is not primary for the given charset
417
if (!(field->charset()->state & MY_CS_PRIMARY))
419
packet->append(STRING_WITH_LEN(" COLLATE "));
420
packet->append(field->charset()->name);
424
if (flags & NOT_NULL_FLAG)
425
packet->append(STRING_WITH_LEN(" NOT NULL"));
426
else if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
429
TIMESTAMP field require explicit NULL flag, because unlike
430
all other fields they are treated as NOT NULL by default.
432
packet->append(STRING_WITH_LEN(" NULL"));
436
Add field flags about FIELD FORMAT (FIXED or DYNAMIC)
437
and about STORAGE (DISK or MEMORY).
439
enum column_format_type column_format= (enum column_format_type)
440
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
443
packet->append(STRING_WITH_LEN(" /*!"));
444
packet->append(STRING_WITH_LEN(" COLUMN_FORMAT"));
445
if (column_format == COLUMN_FORMAT_TYPE_FIXED)
446
packet->append(STRING_WITH_LEN(" FIXED */"));
448
packet->append(STRING_WITH_LEN(" DYNAMIC */"));
451
if (get_field_default_value(table->timestamp_field, field, &def_value, 1))
453
packet->append(STRING_WITH_LEN(" DEFAULT "));
454
packet->append(def_value.ptr(), def_value.length(), system_charset_info);
457
if (table->timestamp_field == field && field->unireg_check != Field::TIMESTAMP_DN_FIELD)
458
packet->append(STRING_WITH_LEN(" ON UPDATE CURRENT_TIMESTAMP"));
460
if (field->unireg_check == Field::NEXT_NUMBER)
461
packet->append(STRING_WITH_LEN(" AUTO_INCREMENT"));
463
if (field->comment.length)
465
packet->append(STRING_WITH_LEN(" COMMENT "));
466
append_unescaped(packet, field->comment.str, field->comment.length);
470
key_info= table->key_info;
471
memset(&create_info, 0, sizeof(create_info));
472
/* Allow update_create_info to update row type */
473
create_info.row_type= share->row_type;
474
cursor->update_create_info(&create_info);
475
primary_key= share->primary_key;
477
for (uint32_t i=0 ; i < share->keys ; i++,key_info++)
479
KEY_PART_INFO *key_part= key_info->key_part;
480
bool found_primary=0;
481
packet->append(STRING_WITH_LEN(",\n "));
483
if (i == primary_key && is_primary_key(key_info))
487
No space at end, because a space will be added after where the
488
identifier would go, but that is not added for primary key.
490
packet->append(STRING_WITH_LEN("PRIMARY KEY"));
492
else if (key_info->flags & HA_NOSAME)
493
packet->append(STRING_WITH_LEN("UNIQUE KEY "));
495
packet->append(STRING_WITH_LEN("KEY "));
498
packet->append_identifier(key_info->name, strlen(key_info->name));
500
packet->append(STRING_WITH_LEN(" ("));
502
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
508
packet->append_identifier(key_part->field->field_name,
509
strlen(key_part->field->field_name));
510
if (key_part->field &&
512
table->field[key_part->fieldnr-1]->key_length()))
515
buff.append(to_string((int32_t) key_part->length /
516
key_part->field->charset()->mbmaxlen));
518
packet->append(buff.c_str(), buff.length());
522
store_key_options(packet, table, key_info);
526
Get possible foreign key definitions stored in InnoDB and append them
527
to the CREATE TABLE statement
530
if ((for_str= cursor->get_foreign_key_create_info()))
532
packet->append(for_str, strlen(for_str));
533
cursor->free_foreign_key_create_info(for_str);
536
packet->append(STRING_WITH_LEN("\n)"));
538
show_table_options= true;
540
Get possible table space definitions and append them
541
to the CREATE TABLE statement
545
We should always store engine since we will now be
546
making sure engines accept options (aka... no
547
dangling arguments for engines.
549
packet->append(STRING_WITH_LEN(" ENGINE="));
550
packet->append(cursor->engine->getName().c_str());
552
if (share->db_create_options & HA_OPTION_PACK_KEYS)
553
packet->append(STRING_WITH_LEN(" PACK_KEYS=1"));
554
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
555
packet->append(STRING_WITH_LEN(" PACK_KEYS=0"));
556
if (create_info.row_type != ROW_TYPE_DEFAULT)
558
packet->append(STRING_WITH_LEN(" ROW_FORMAT="));
559
packet->append(ha_row_type[(uint32_t) create_info.row_type]);
561
if (table->s->hasKeyBlockSize())
563
packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
564
buff= to_string(table->s->getKeyBlockSize());
565
packet->append(buff.c_str(), buff.length());
567
if (share->block_size)
569
packet->append(STRING_WITH_LEN(" BLOCK_SIZE="));
570
buff= to_string(share->block_size);
571
packet->append(buff.c_str(), buff.length());
573
table->cursor->append_create_info(packet);
574
if (share->hasComment() && share->getCommentLength())
576
packet->append(STRING_WITH_LEN(" COMMENT="));
577
append_unescaped(packet, share->getComment(),
578
share->getCommentLength());
581
table->restore_column_map(old_map);
585
static void store_key_options(String *packet, Table *table, KEY *key_info)
589
if (key_info->algorithm == HA_KEY_ALG_BTREE)
590
packet->append(STRING_WITH_LEN(" USING BTREE"));
592
if (key_info->algorithm == HA_KEY_ALG_HASH)
593
packet->append(STRING_WITH_LEN(" USING HASH"));
595
if ((key_info->flags & HA_USES_BLOCK_SIZE) &&
596
table->s->getKeyBlockSize() != key_info->block_size)
598
packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
599
end= internal::int64_t10_to_str(key_info->block_size, buff, 10);
600
packet->append(buff, (uint32_t) (end - buff));
603
assert(test(key_info->flags & HA_USES_COMMENT) ==
604
(key_info->comment.length > 0));
605
if (key_info->flags & HA_USES_COMMENT)
607
packet->append(STRING_WITH_LEN(" COMMENT "));
608
append_unescaped(packet, key_info->comment.str,
609
key_info->comment.length);
614
/****************************************************************************
615
Return info about all processes
616
returns for each thread: thread id, user, host, db, command, info
617
****************************************************************************/
632
thread_info(uint64_t thread_id_arg,
633
time_t start_time_arg,
634
uint32_t command_arg,
635
const string &user_arg,
636
const string &host_arg,
637
const string &db_arg,
638
const string &proc_info_arg,
639
const string &state_info_arg,
640
const string &query_arg)
641
: thread_id(thread_id_arg), start_time(start_time_arg), command(command_arg),
642
user(user_arg), host(host_arg), db(db_arg), proc_info(proc_info_arg),
643
state_info(state_info_arg), query(query_arg)
647
/*****************************************************************************
649
*****************************************************************************/
651
static vector<drizzle_show_var *> all_status_vars;
652
static vector<drizzle_show_var *> com_status_vars;
653
static bool status_vars_inited= 0;
654
static int show_var_cmp(const void *var1, const void *var2)
656
return strcmp(((drizzle_show_var*)var1)->name, ((drizzle_show_var*)var2)->name);
659
class show_var_cmp_functor
662
show_var_cmp_functor() { }
663
inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const
665
int val= strcmp(var1->name, var2->name);
670
class show_var_remove_if
673
show_var_remove_if() { }
674
inline bool operator()(const drizzle_show_var *curr) const
676
return (curr->type == SHOW_UNDEF);
680
drizzle_show_var *getFrontOfStatusVars()
682
return all_status_vars.front();
685
drizzle_show_var *getCommandStatusVars()
687
return com_status_vars.front();
691
Adds an array of drizzle_show_var entries to the output of SHOW STATUS
694
add_status_vars(drizzle_show_var *list)
695
list - an array of drizzle_show_var entries to add to all_status_vars
696
the last entry must be {0,0,SHOW_UNDEF}
699
The handling of all_status_vars[] is completely internal, it's allocated
700
automatically when something is added to it, and deleted completely when
701
the last entry is removed.
703
As a special optimization, if add_status_vars() is called before
704
init_status_vars(), it assumes "startup mode" - neither concurrent access
705
to the array nor SHOW STATUS are possible (thus it skips locks and qsort)
707
int add_status_vars(drizzle_show_var *list)
710
if (status_vars_inited)
711
pthread_mutex_lock(&LOCK_status);
713
all_status_vars.insert(all_status_vars.begin(), list++);
714
if (status_vars_inited)
715
sort(all_status_vars.begin(), all_status_vars.end(),
716
show_var_cmp_functor());
717
if (status_vars_inited)
718
pthread_mutex_unlock(&LOCK_status);
722
int add_com_status_vars(drizzle_show_var *list)
727
com_status_vars.insert(com_status_vars.begin(), list++);
728
if (status_vars_inited)
729
sort(com_status_vars.begin(), com_status_vars.end(),
730
show_var_cmp_functor());
736
Make all_status_vars[] usable for SHOW STATUS
739
See add_status_vars(). Before init_status_vars() call, add_status_vars()
740
works in a special fast "startup" mode. Thus init_status_vars()
741
should be called as late as possible but before enabling multi-threading.
743
void init_status_vars()
745
status_vars_inited= 1;
746
sort(all_status_vars.begin(), all_status_vars.end(),
747
show_var_cmp_functor());
748
sort(com_status_vars.begin(), com_status_vars.end(),
749
show_var_cmp_functor());
752
void reset_status_vars()
754
vector<drizzle_show_var *>::iterator p;
756
p= all_status_vars.begin();
757
while (p != all_status_vars.end())
759
/* Note that SHOW_LONG_NOFLUSH variables are not reset */
760
if ((*p)->type == SHOW_LONG)
765
p= com_status_vars.begin();
766
while (p != com_status_vars.end())
768
/* Note that SHOW_LONG_NOFLUSH variables are not reset */
769
if ((*p)->type == SHOW_LONG)
776
catch-all cleanup function, cleans up everything no matter what
779
This function is not strictly required if all add_to_status/
780
remove_status_vars are properly paired, but it's a safety measure that
781
deletes everything from the all_status_vars vector even if some
782
remove_status_vars were forgotten
784
void free_status_vars()
786
all_status_vars.clear();
787
com_status_vars.clear();
791
Removes an array of drizzle_show_var entries from the output of SHOW STATUS
794
remove_status_vars(drizzle_show_var *list)
795
list - an array of drizzle_show_var entries to remove to all_status_vars
796
the last entry must be {0,0,SHOW_UNDEF}
799
there's lots of room for optimizing this, especially in non-sorted mode,
800
but nobody cares - it may be called only in case of failed plugin
801
initialization in the mysqld startup.
804
void remove_status_vars(drizzle_show_var *list)
806
if (status_vars_inited)
808
pthread_mutex_lock(&LOCK_status);
809
drizzle_show_var *all= all_status_vars.front();
810
int a= 0, b= all_status_vars.size(), c= (a+b)/2;
812
for (; list->name; list++)
815
for (a= 0, b= all_status_vars.size(); b-a > 1; c= (a+b)/2)
817
res= show_var_cmp(list, all+c);
826
all[c].type= SHOW_UNDEF;
828
/* removes all the SHOW_UNDEF elements from the vector */
829
all_status_vars.erase(std::remove_if(all_status_vars.begin(),
830
all_status_vars.end(),show_var_remove_if()),
831
all_status_vars.end());
832
pthread_mutex_unlock(&LOCK_status);
836
drizzle_show_var *all= all_status_vars.front();
838
for (; list->name; list++)
840
for (i= 0; i < all_status_vars.size(); i++)
842
if (show_var_cmp(list, all+i))
844
all[i].type= SHOW_UNDEF;
848
/* removes all the SHOW_UNDEF elements from the vector */
849
all_status_vars.erase(std::remove_if(all_status_vars.begin(),
850
all_status_vars.end(),show_var_remove_if()),
851
all_status_vars.end());
855
/* collect status for all running threads */
857
void calc_sum_of_all_status(system_status_var *to)
859
/* Ensure that thread id not killed during loop */
860
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
862
/* Get global values as base */
863
*to= global_status_var;
865
/* Add to this status from existing threads */
866
for(SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
868
add_to_status(to, &((*it)->status_var));
871
pthread_mutex_unlock(&LOCK_thread_count);
649
875
} /* namespace drizzled */