summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2002-02-11 13:48:59 +0200
committerunknown <monty@hundin.mysql.fi>2002-02-11 13:48:59 +0200
commite0ccdc17a208abb21cf15e7fbbbc3b88b969e0ec (patch)
treeada172b5dc5dccd546e301548aac618812e19814 /sql
parentaf932b5db200407cb250d6e398383e8db387e680 (diff)
parent501650c5b16a4c7cf7b673b19f9a2ae9c319e24f (diff)
downloadmariadb-git-e0ccdc17a208abb21cf15e7fbbbc3b88b969e0ec.tar.gz
merge with 3.23.48
BUILD/FINISH.sh: Auto merged BUILD/SETUP.sh: Auto merged BUILD/compile-alpha: Auto merged BUILD/compile-pentium-gcov: Auto merged BUILD/compile-pentium-gprof: Auto merged BUILD/compile-pentium: Auto merged BitKeeper/deleted/.del-my_new.cc: Delete: mysys/my_new.cc Build-tools/Do-compile: Auto merged acconfig.h: Auto merged acinclude.m4: Auto merged Docs/manual.texi: Auto merged bdb/dist/configure.in: Auto merged client/Makefile.am: Auto merged innobase/btr/btr0cur.c: Auto merged innobase/buf/buf0lru.c: Auto merged innobase/dict/dict0crea.c: Auto merged innobase/fil/fil0fil.c: Auto merged innobase/include/srv0srv.h: Auto merged innobase/rem/rem0cmp.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/srv/srv0start.c: Auto merged innobase/trx/trx0purge.c: Auto merged myisam/myisampack.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/t/join.test: Auto merged mysys/Makefile.am: Auto merged scripts/Makefile.am: Auto merged sql/ha_innodb.h: Auto merged sql/handler.cc: Auto merged sql/my_lock.c: Auto merged sql/mysqld.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_table.cc: Auto merged support-files/my-huge.cnf.sh: Auto merged support-files/my-large.cnf.sh: Auto merged support-files/my-medium.cnf.sh: Auto merged support-files/my-small.cnf.sh: Auto merged configure.in: merge innobase/row/row0mysql.c: merge innobase/trx/trx0trx.c: merge mysql-test/r/innodb.result: merge mysql-test/r/join.result: merge sql/ha_innodb.cc: merge sql/slave.cc: merge
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_innodb.cc168
-rw-r--r--sql/ha_innodb.h5
-rw-r--r--sql/handler.cc43
-rw-r--r--sql/my_lock.c17
-rw-r--r--sql/mysqld.cc9
-rw-r--r--sql/sql_select.cc10
-rw-r--r--sql/sql_table.cc33
7 files changed, 148 insertions, 137 deletions
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index f99e677913e..e2657e5cad7 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & InnoDB Oy
+/* Copyright (C) 2000 MySQL AB & InnoDB Oy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -85,8 +85,8 @@ long innobase_mirrored_log_groups, innobase_log_files_in_group,
char *innobase_data_home_dir;
char *innobase_log_group_home_dir, *innobase_log_arch_dir;
char *innobase_unix_file_flush_method;
-bool innobase_flush_log_at_trx_commit, innobase_log_archive,
- innobase_use_native_aio, innobase_fast_shutdown;
+my_bool innobase_flush_log_at_trx_commit, innobase_log_archive,
+ innobase_use_native_aio, innobase_fast_shutdown;
/*
Set default InnoDB size to 64M, to let users use InnoDB without having
@@ -235,7 +235,7 @@ convert_error_code_to_mysql(
extern "C" {
/*****************************************************************
Prints info of a THD object (== user session thread) to the
-standatd output. NOTE that mysql/innobase/trx/trx0trx.c must contain
+standard output. NOTE that mysql/innobase/trx/trx0trx.c must contain
the prototype for this function! */
void
@@ -304,6 +304,8 @@ check_trx_exists(
thd->transaction.stmt.innobase_tid =
(void*)&innodb_dummy_stmt_trx_handle;
+ } else {
+ ut_a(trx->magic_n == TRX_MAGIC_N);
}
return(trx);
@@ -841,6 +843,7 @@ innobase_close_connection(
whose transaction should be rolled back */
{
if (NULL != thd->transaction.all.innobase_tid) {
+
trx_rollback_for_mysql((trx_t*)
(thd->transaction.all.innobase_tid));
trx_free_for_mysql((trx_t*)
@@ -2465,44 +2468,6 @@ ha_innobase::position(
ref_stored_len = len;
}
-/***********************************************************************
-Tells something additional to the handler about how to do things. */
-
-int
-ha_innobase::extra(
-/*===============*/
- /* out: 0 or error number */
- enum ha_extra_function operation)
- /* in: HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE */
-{
- row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
-
- switch (operation) {
- case HA_EXTRA_RESET:
- case HA_EXTRA_RESET_STATE:
- prebuilt->read_just_key = 0;
- break;
- case HA_EXTRA_NO_KEYREAD:
- prebuilt->read_just_key = 0;
- break;
- case HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE:
- prebuilt->in_update_remember_pos = FALSE;
- break;
- case HA_EXTRA_KEYREAD:
- prebuilt->read_just_key = 1;
- break;
- default:/* Do nothing */
- ;
- }
-
- return(0);
-}
-
-int ha_innobase::reset(void)
-{
- return(0);
-}
-
/*********************************************************************
Creates a table definition to an InnoDB database. */
@@ -2981,9 +2946,9 @@ ha_innobase::records_in_range(
DBUG_ENTER("records_in_range");
- if (prebuilt->trx) {
- prebuilt->trx->op_info = (char*) "estimating range size";
- }
+ /* Warning: since it is not sure that MySQL calls external_lock
+ before calling this function, the trx field in prebuilt can be
+ obsolete! */
active_index = keynr;
@@ -3017,10 +2982,6 @@ ha_innobase::records_in_range(
my_free((char*) key_val_buff2, MYF(0));
- if (prebuilt->trx) {
- prebuilt->trx->op_info = (char*) "";
- }
-
DBUG_RETURN((ha_rows) n_rows);
}
@@ -3041,10 +3002,9 @@ ha_innobase::estimate_number_of_rows(void)
ulonglong estimate;
ulonglong data_file_length;
- if (prebuilt->trx) {
- prebuilt->trx->op_info =
- (char*) "estimating upper bound of table size";
- }
+ /* Warning: since it is not sure that MySQL calls external_lock
+ before calling this function, the trx field in prebuilt can be
+ obsolete! */
DBUG_ENTER("info");
@@ -3061,10 +3021,6 @@ ha_innobase::estimate_number_of_rows(void)
estimate = 2 * data_file_length / dict_index_calc_min_rec_len(index);
- if (prebuilt->trx) {
- prebuilt->trx->op_info = (char*) "";
- }
-
DBUG_RETURN((ha_rows) estimate);
}
@@ -3080,10 +3036,12 @@ ha_innobase::scan_time()
{
row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
- /* In the following formula we assume that scanning 10 pages
- takes the same time as a disk seek: */
-
- return((double) (prebuilt->table->stat_clustered_index_size / 10));
+ /* Since MySQL seems to favor table scans too much over index
+ searches, we pretend that a sequential read takes the same time
+ as a random disk read, that is, we do not divide the following
+ by 10, which would be physically realistic. */
+
+ return((double) (prebuilt->table->stat_clustered_index_size));
}
/*************************************************************************
@@ -3104,9 +3062,9 @@ ha_innobase::info(
DBUG_ENTER("info");
- if (prebuilt->trx) {
- prebuilt->trx->op_info = (char*) "calculating table stats";
- }
+ /* Warning: since it is not sure that MySQL calls external_lock
+ before calling this function, the trx field in prebuilt can be
+ obsolete! */
ib_table = prebuilt->table;
@@ -3154,25 +3112,17 @@ ha_innobase::info(
index->stat_n_diff_key_vals[j + 1]);
}
+ /* Since MySQL seems to favor table scans
+ too much over index searches, we pretend
+ index selectivity is 2 times better than
+ our estimate: */
+
+ rec_per_key = rec_per_key / 2;
+
if (rec_per_key == 0) {
rec_per_key = 1;
}
- /* Since the MySQL optimizer is often too
- pessimistic in the assumption that a table
- does not fit in the buffer pool, we
- increase the attractiveness of indexes
- by assuming the selectivity of any prefix
- of an index is 1 / 100 or better.
- (Actually, we should look at the table
- size, and if the table is smaller than
- the buffer pool, we should uniformly
- increase the attractiveness of indexes,
- regardless of the estimated selectivity.) */
-
- if (rec_per_key > records / 100) {
- rec_per_key = records / 100;
- }
table->key_info[i].rec_per_key[j]
= rec_per_key;
}
@@ -3188,15 +3138,13 @@ ha_innobase::info(
pointer and cause a seg fault. */
if (flag & HA_STATUS_ERRKEY) {
+ ut_a(prebuilt->trx && prebuilt->trx->magic_n == TRX_MAGIC_N);
+
errkey = (unsigned int) row_get_mysql_key_number_for_index(
(dict_index_t*)
trx_get_error_info(prebuilt->trx));
}
- if (prebuilt->trx) {
- prebuilt->trx->op_info = (char*) "";
- }
-
DBUG_VOID_RETURN;
}
@@ -3217,6 +3165,8 @@ ha_innobase::check(
row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
ulint ret;
+ ut_a(prebuilt->trx && prebuilt->trx->magic_n == TRX_MAGIC_N);
+
if (prebuilt->mysql_template == NULL) {
/* Build the template; we will use a dummy template
in index scans done in checking */
@@ -3250,6 +3200,10 @@ ha_innobase::update_table_comment(
char* str = my_malloc(length + 550, MYF(0));
char* pos;
+ /* Warning: since it is not sure that MySQL calls external_lock
+ before calling this function, the trx field in prebuilt can be
+ obsolete! */
+
if (!str) {
return((char*)comment);
}
@@ -3271,6 +3225,53 @@ ha_innobase::update_table_comment(
return(str);
}
+/***********************************************************************
+Tells something additional to the handler about how to do things. */
+
+int
+ha_innobase::extra(
+/*===============*/
+ /* out: 0 or error number */
+ enum ha_extra_function operation)
+ /* in: HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE */
+{
+ row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
+
+ /* Warning: since it is not sure that MySQL calls external_lock
+ before calling this function, the trx field in prebuilt can be
+ obsolete! */
+
+ switch (operation) {
+ case HA_EXTRA_RESET:
+ case HA_EXTRA_RESET_STATE:
+ prebuilt->read_just_key = 0;
+ break;
+ case HA_EXTRA_NO_KEYREAD:
+ prebuilt->read_just_key = 0;
+ break;
+ case HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE:
+ prebuilt->in_update_remember_pos = FALSE;
+ break;
+ case HA_EXTRA_KEYREAD:
+ prebuilt->read_just_key = 1;
+ break;
+ default:/* Do nothing */
+ ;
+ }
+
+ return(0);
+}
+
+/**********************************************************************
+????????????? */
+
+int
+ha_innobase::reset(void)
+/*====================*/
+{
+ return(0);
+}
+
/**********************************************************************
As MySQL will execute an external lock for every new table it uses when it
starts to process an SQL statement, we can use this function to store the
@@ -3496,5 +3497,4 @@ ha_innobase::get_auto_increment()
return(nr);
}
-
#endif /* HAVE_INNOBASE_DB */
diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h
index f926f303b26..faae42575b5 100644
--- a/sql/ha_innodb.h
+++ b/sql/ha_innodb.h
@@ -178,8 +178,9 @@ extern long innobase_force_recovery, innobase_thread_concurrency;
extern char *innobase_data_home_dir, *innobase_data_file_path;
extern char *innobase_log_group_home_dir, *innobase_log_arch_dir;
extern char *innobase_unix_file_flush_method;
-extern bool innobase_flush_log_at_trx_commit, innobase_log_archive,
- innobase_use_native_aio, innobase_fast_shutdown;
+/* The following variables have to be my_bool for SHOW VARIABLES to work */
+extern my_bool innobase_flush_log_at_trx_commit, innobase_log_archive,
+ innobase_use_native_aio, innobase_fast_shutdown;
extern TYPELIB innobase_lock_typelib;
diff --git a/sql/handler.cc b/sql/handler.cc
index 507b77c977b..8447797442c 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -222,28 +222,31 @@ int ha_autocommit_or_rollback(THD *thd, int error)
DBUG_RETURN(error);
}
-/* This function is called when MySQL writes the log segment of a transaction
-to the binlog. It is called when the LOCK_log mutex is reserved. Here we
-communicate to transactional table handlers whta binlog position corresponds
-to the current transaction. The handler can store it and in recovery print
-to the user, so that the user knows from what position in the binlog to
-start possible roll-forward, for example, if the crashed server was a slave
-in replication. This function also calls the commit of the table handler,
-because the order of trasnactions in the log of the table handler must be
-the same as in the binlog. */
-
-int ha_report_binlog_offset_and_commit(
- THD *thd, /* in: user thread */
- char *log_file_name, /* in: latest binlog file name */
- my_off_t end_offset) /* in: the offset in the binlog file
- up to which we wrote */
+/*
+ This function is called when MySQL writes the log segment of a
+ transaction to the binlog. It is called when the LOCK_log mutex is
+ reserved. Here we communicate to transactional table handlers whta
+ binlog position corresponds to the current transaction. The handler
+ can store it and in recovery print to the user, so that the user
+ knows from what position in the binlog to start possible
+ roll-forward, for example, if the crashed server was a slave in
+ replication. This function also calls the commit of the table
+ handler, because the order of trasnactions in the log of the table
+ handler must be the same as in the binlog.
+
+ arguments:
+ log_file_name: latest binlog file name
+ end_offset: the offset in the binlog file up to which we wrote
+*/
+
+int ha_report_binlog_offset_and_commit(THD *thd,
+ char *log_file_name,
+ my_off_t end_offset)
{
+ int error= 0;
+#ifdef HAVE_INNOBASE_DB
THD_TRANS *trans;
- int error = 0;
-
trans = &thd->transaction.all;
-
-#ifdef HAVE_INNOBASE_DB
if (trans->innobase_tid)
{
if ((error=innobase_report_binlog_offset_and_commit(thd,
@@ -257,10 +260,10 @@ int ha_report_binlog_offset_and_commit(
trans->innodb_active_trans=0;
}
#endif
-
return error;
}
+
int ha_commit_trans(THD *thd, THD_TRANS* trans)
{
int error=0;
diff --git a/sql/my_lock.c b/sql/my_lock.c
index 9b4ac502e57..4d451fcff22 100644
--- a/sql/my_lock.c
+++ b/sql/my_lock.c
@@ -26,10 +26,6 @@
#include <thr_alarm.h>
#include <errno.h>
-#ifdef HAVE_FCNTL
-static struct flock lock; /* Must be static for sun-sparc */
-#endif
-
/* Lock a part of a file */
int my_lock(File fd,int locktype,my_off_t start,my_off_t length,myf MyFlags)
@@ -37,24 +33,25 @@ int my_lock(File fd,int locktype,my_off_t start,my_off_t length,myf MyFlags)
thr_alarm_t alarmed;
ALARM alarm_buff;
uint wait_for_alarm;
+ struct flock m_lock;
DBUG_ENTER("my_lock");
DBUG_PRINT("my",("Fd: %d Op: %d start: %ld Length: %ld MyFlags: %d",
fd,locktype,(ulong) start,(ulong) length,MyFlags));
if (my_disable_locking)
DBUG_RETURN(0); /* purecov: inspected */
- lock.l_type=(short) locktype;
- lock.l_whence=0L;
- lock.l_start=(long) start;
- lock.l_len=(long) length;
+ m_lock.l_type=(short) locktype;
+ m_lock.l_whence=0L;
+ m_lock.l_start=(long) start;
+ m_lock.l_len=(long) length;
wait_for_alarm=(MyFlags & MY_DONT_WAIT ? MY_HOW_OFTEN_TO_ALARM :
(uint) 12*60*60);
- if (fcntl(fd,F_SETLK,&lock) != -1) /* Check if we can lock */
+ if (fcntl(fd,F_SETLK,&m_lock) != -1) /* Check if we can lock */
DBUG_RETURN(0); /* Ok, file locked */
DBUG_PRINT("info",("Was locked, trying with alarm"));
if (!thr_alarm(&alarmed,wait_for_alarm,&alarm_buff))
{
int value;
- while ((value=fcntl(fd,F_SETLKW,&lock)) && !thr_got_alarm(&alarmed) &&
+ while ((value=fcntl(fd,F_SETLKW,&m_lock)) && !thr_got_alarm(&alarmed) &&
errno == EINTR) ;
thr_end_alarm(&alarmed);
if (value != -1)
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index d30d285d0b8..d1d3d6072d6 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3309,10 +3309,11 @@ static void use_help(void)
static void usage(void)
{
print_version();
- puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB, by Monty and others");
- puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,");
- puts("and you are welcome to modify and redistribute it under the GPL license\n");
- puts("Starts the MySQL server\n");
+ puts("\
+Copyright (C) 2000 MySQL AB, by Monty and others\n\
+This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
+and you are welcome to modify and redistribute it under the GPL license\n\
+Starts the MySQL server\n");
printf("Usage: %s [OPTIONS]\n", my_progname);
puts("\n\
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e2e5e4bf55a..69cac90e2be 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -5962,10 +5962,10 @@ SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length)
/*****************************************************************************
-** Fill join cache with packed records
-** Records are stored in tab->cache.buffer and last record in
-** last record is stored with pointers to blobs to support very big
-** records
+ Fill join cache with packed records
+ Records are stored in tab->cache.buffer and last record in
+ last record is stored with pointers to blobs to support very big
+ records
******************************************************************************/
static int
@@ -6027,7 +6027,7 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count)
if (null_fields && tables[i].table->null_fields)
{ /* must copy null bits */
copy->str=(char*) tables[i].table->null_flags;
- copy->length=(tables[i].table->null_fields+7)/8;
+ copy->length=tables[i].table->null_bytes;
copy->strip=0;
copy->blob_field=0;
length+=copy->length;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 0335c6f49cf..8013afa194b 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -825,7 +825,7 @@ bool close_cached_table(THD *thd,TABLE *table)
/* Mark all tables that are in use as 'old' */
mysql_lock_abort(thd,table); // end threads waiting on lock
-#ifdef REMOVE_LOCKS
+#if defined(USING_TRANSACTIONS) || defined( __WIN__) || defined( __EMX__) || !defined(OS2)
/* Wait until all there are no other threads that has this table open */
while (remove_table_from_cache(thd,table->table_cache_key,
table->table_name))
@@ -1674,20 +1674,29 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
}
-#if defined( __WIN__) || defined( __EMX__) || defined( OS2)
- // Win32 can't rename an open table, so we must close the org table!
- table_name=thd->strdup(table_name); // must be saved
- if (close_cached_table(thd,table))
- { // Aborted
- VOID(quick_rm_table(new_db_type,new_db,tmp_name));
- VOID(pthread_mutex_unlock(&LOCK_open));
- goto err;
+#if (!defined( __WIN__) && !defined( __EMX__) && !defined( OS2))
+ if (table->file->has_transactions())
+#endif
+ {
+ /*
+ Win32 and InnoDB can't drop a table that is in use, so we must
+ close all the original table at before doing the rename
+ */
+ table_name=thd->strdup(table_name); // must be saved
+ if (close_cached_table(thd,table))
+ { // Aborted
+ VOID(quick_rm_table(new_db_type,new_db,tmp_name));
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ goto err;
+ }
+ table=0; // Marker that table is closed
}
- table=0; // Marker for win32 version
-#else
- table->file->extra(HA_EXTRA_FORCE_REOPEN); // Don't use this file anymore
+#if (!defined( __WIN__) && !defined( __EMX__) && !defined( OS2))
+ else
+ table->file->extra(HA_EXTRA_FORCE_REOPEN); // Don't use this file anymore
#endif
+
error=0;
if (mysql_rename_table(old_db_type,db,table_name,db,old_name))
{