Commit ab54e167 authored by unknown's avatar unknown
Browse files

Fixes while reviewing new code

Added option --count to mysqlshow (to show number of rows)
Fixed possible core dump in information schema


client/client_priv.h:
  --count for mysqlshow
client/mysqlshow.c:
  Added option --count to be used when the user want's number of rows per table in the output
  (We shouldn't use count(*) as default as this can be a slow operation)
mysys/my_thr_init.c:
  Correct comment
sql/ha_berkeley.cc:
  Remove not used variable
sql/ha_berkeley.h:
  Remove not used variable
sql/ha_innodb.cc:
  Remove not used function
sql/ha_ndbcluster.cc:
  false -> FALSE
  true -> TRUE
sql/handler.cc:
  Added and fixed comments
  Remove 'strange' code to remove compiler warnings (better to do things like this with attribute)
sql/item.cc:
  false -> FALSE
sql/item_cmpfunc.cc:
  Fixed indentation
sql/item_cmpfunc.h:
  marked BETWEEN as a bool function
sql/item_func.cc:
  Simple optimzation
sql/key.cc:
  Removed wrong code
sql/log.cc:
  Check result from open_index_file()
sql/mysql_priv.h:
  Simplyfy some test of netware
sql/mysqld.cc:
  Fixed indentation
  Check result form open_index_file()
  Simplify code with IF_NETWARE()
sql/opt_range.cc:
  false -> FALSE
  true -> TRUE
  Fixed indentation
sql/opt_sum.cc:
  Fixed comments
sql/sp_head.cc:
  Simple optimzation
  Move variable declarations to begining of blocks
sql/sql_acl.cc:
  Fix long lines
  Rename xx -> column
  Move declaration to beginning of block
sql/sql_parse.cc:
  Removed comment
sql/sql_select.cc:
  Indentation fixes
sql/sql_show.cc:
  Fixed reference outside of array (possible core dump)
sql/sql_table.cc:
  Simplify code
  Combine common code
sql/sql_test.cc:
  false -> FALSE
sql/sql_trigger.cc:
  false -> false
  true -> TRUE
sql/sql_yacc.yy:
  Simpler test
sql/unireg.cc:
  Added comment
parent 21eed96b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -45,9 +45,9 @@ enum options_client
  OPT_COMPATIBLE, OPT_RECONNECT, OPT_DELIMITER, OPT_SECURE_AUTH,
  OPT_OPEN_FILES_LIMIT, OPT_SET_CHARSET, OPT_CREATE_OPTIONS,
  OPT_START_POSITION, OPT_STOP_POSITION, OPT_START_DATETIME, OPT_STOP_DATETIME,
  OPT_SIGINT_IGNORE, OPT_HEXBLOB, OPT_ORDER_BY_PRIMARY
  OPT_SIGINT_IGNORE, OPT_HEXBLOB, OPT_ORDER_BY_PRIMARY, OPT_COUNT,
#ifdef HAVE_NDBCLUSTER_DB
  ,OPT_NDBCLUSTER,OPT_NDB_CONNECTSTRING
  OPT_NDBCLUSTER, OPT_NDB_CONNECTSTRING,
#endif
  ,OPT_IGNORE_TABLE
  OPT_IGNORE_TABLE
};
+38 −27
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@
#include <sslopt-vars.h>

static my_string host=0,opt_password=0,user=0;
static my_bool opt_show_keys= 0, opt_compress= 0, opt_status= 0, 
static my_bool opt_show_keys= 0, opt_compress= 0, opt_count=0, opt_status= 0, 
  tty_password= 0, opt_table_type= 0;
static uint opt_verbose=0;
static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
@@ -71,8 +71,7 @@ int main(int argc, char **argv)
    char *pos= argv[argc-1], *to;
    for (to= pos ; *pos ; pos++, to++)
    {
      switch (*pos)
      {
      switch (*pos) {
      case '*':
	*pos= '%';
	first_argument_uses_wildcards= 1;
@@ -163,6 +162,10 @@ static struct my_option my_long_options[] =
  {"default-character-set", OPT_DEFAULT_CHARSET,
   "Set the default character set.", (gptr*) &default_charset,
   (gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"count", OPT_COUNT,
   "Show number of rows per table (may be slow for not MyISAM tables)",
   (gptr*) &opt_count, (gptr*) &opt_count, 0, GET_BOOL, NO_ARG, 0, 0, 0,
   0, 0, 0},
  {"compress", 'C', "Use compression in server/client protocol.",
   (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
   0, 0, 0},
@@ -308,6 +311,14 @@ get_options(int *argc,char ***argv)
  
  if (tty_password)
    opt_password=get_tty_password(NullS);
  if (opt_count)
  {
    /*
      We need to set verbose to 2 as we need to change the output to include
      the number-of-rows column
    */
    opt_verbose= 2;
  }
  return;
}

@@ -322,7 +333,7 @@ list_dbs(MYSQL *mysql,const char *wild)
  char query[255];
  MYSQL_FIELD *field;
  MYSQL_RES *result;
  MYSQL_ROW row, trow, rrow;
  MYSQL_ROW row, rrow;

  if (!(result=mysql_list_dbs(mysql,wild)))
  {
@@ -352,11 +363,6 @@ list_dbs(MYSQL *mysql,const char *wild)

    if (opt_verbose)
    {
      /*
       *  Original code by MG16373;  Slightly modified by Monty.
       *  Print now the count of tables and rows for each database.
       */

      if (!(mysql_select_db(mysql,row[0])))
      {
	MYSQL_RES *tresult = mysql_list_tables(mysql,(char*)NULL);
@@ -366,6 +372,8 @@ list_dbs(MYSQL *mysql,const char *wild)
	  rowcount = 0;
	  if (opt_verbose > 1)
	  {
            /* Print the count of tables and rows for each database */
            MYSQL_ROW trow;
	    while ((trow = mysql_fetch_row(tresult)))
	    {
	      sprintf(query,"SELECT COUNT(*) FROM `%s`",trow[0]);
@@ -487,10 +495,6 @@ list_tables(MYSQL *mysql,const char *db,const char *table)

  while ((row = mysql_fetch_row(result)))
  {
    /*
     *   Modified by MG16373
     *   Print now the count of rows for each table.
     */
    counter++;
    if (opt_verbose > 0)
    {
@@ -510,6 +514,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table)

	  if (opt_verbose > 1)
	  {
            /* Print the count of rows for each table */
	    sprintf(query,"SELECT COUNT(*) FROM `%s`",row[0]);
	    if (!(mysql_query(mysql,query)))
	    {
@@ -574,7 +579,7 @@ list_table_status(MYSQL *mysql,const char *db,const char *wild)
  MYSQL_RES *result;
  MYSQL_ROW row;

  end=strxmov(query,"show table status from ",db,NullS);
  end=strxmov(query,"show table status from `",db,"`",NullS);
  if (wild && wild[0])
    strxmov(end," like '",wild,"'",NullS);
  if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
@@ -600,8 +605,8 @@ list_table_status(MYSQL *mysql,const char *db,const char *wild)
}

/*
** list fields uses field interface as an example of how to parse
** a MYSQL FIELD
  list fields uses field interface as an example of how to parse
  a MYSQL FIELD
*/

static int
@@ -612,6 +617,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
  MYSQL_RES *result;
  MYSQL_ROW row;
  ulong rows;
  LINT_INIT(rows);

  if (mysql_select_db(mysql,db))
  {
@@ -619,6 +625,9 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
	    mysql_error(mysql));
    return 1;
  }

  if (opt_count)
  {
    sprintf(query,"select count(*) from `%s`", table);
    if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
    {
@@ -629,6 +638,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
    row= mysql_fetch_row(result);
    rows= (ulong) strtoull(row[0], (char**) 0, 10);
    mysql_free_result(result);
  }

  end=strmov(strmov(strmov(query,"show /*!32332 FULL */ columns from `"),table),"`");
  if (wild && wild[0])
@@ -640,8 +650,9 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
    return 1;
  }

  printf("Database: %s  Table: %s Rows: %lu", db, table, rows);

  printf("Database: %s  Table: %s", db, table);
  if (opt_count)
    printf("  Rows: %lu", rows);
  if (wild && wild[0])
    printf("  Wildcard: %s",wild);
  putchar('\n');
@@ -675,7 +686,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,


/*****************************************************************************
** General functions to print a nice ascii-table from data
 General functions to print a nice ascii-table from data
*****************************************************************************/

static void
+5 −6
Original line number Diff line number Diff line
@@ -67,12 +67,11 @@ my_bool my_thread_global_init(void)
  /*
    Set mutex type to "fast" a.k.a "adaptive"

    The mutex kind determines what happens if a thread attempts to lock
    a mutex it already owns with pthread_mutex_lock(3). If the mutex
    is of the ``fast'' kind, pthread_mutex_lock(3) simply suspends
    the calling thread forever. If the mutex is of the ``error checking''
    kind, pthread_mutex_lock(3) returns immediately with the error
    code EDEADLK.
    In this case the thread may steal the mutex from some other thread
    that is waiting for the same mutex.  This will save us some
    context switches but may cause a thread to 'starve forever' while
    waiting for the mutex (not likely if the code within the mutex is
    short).
  */
  pthread_mutexattr_init(&my_fast_mutexattr);
  pthread_mutexattr_settype(&my_fast_mutexattr,
+1 −3
Original line number Diff line number Diff line
@@ -2013,8 +2013,6 @@ THR_LOCK_DATA **ha_berkeley::store_lock(THD *thd, THR_LOCK_DATA **to,
	!thd->in_lock_tables)
      lock_type = TL_WRITE_ALLOW_WRITE;
    lock.type= lock_type;
    lock_on_read= ((table->reginfo.lock_type > TL_WRITE_ALLOW_READ) ? DB_RMW :
		   0);
  }
  *to++= &lock;
  return to;
+0 −1
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ class ha_berkeley: public handler
  ulong alloced_rec_buff_length;
  ulong changed_rows;
  uint primary_key,last_dup_key, hidden_primary_key, version;
  u_int32_t lock_on_read;
  bool key_read, using_ignore;
  bool fix_rec_buff_for_blob(ulong length);
  byte current_ident[BDB_HIDDEN_PRIMARY_KEY_LENGTH];
Loading