Commit d495656a authored by monty@mashka.mysql.fi's avatar monty@mashka.mysql.fi

Cleanups

parent d9e70722
...@@ -273,11 +273,14 @@ CREATE TABLE t2 (a int primary key, b int, c int); ...@@ -273,11 +273,14 @@ CREATE TABLE t2 (a int primary key, b int, c int);
INSERT t2 VALUES (3,4,5); INSERT t2 VALUES (3,4,5);
SELECT DISTINCT t1.a, t2.b FROM t1, t2 WHERE t1.a=1 ORDER BY t2.c; SELECT DISTINCT t1.a, t2.b FROM t1, t2 WHERE t1.a=1 ORDER BY t2.c;
DROP TABLE IF EXISTS t1,t2; DROP TABLE IF EXISTS t1,t2;
#
# Test of LEFT() with distinct
#
CREATE table t1 ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM AUTO_INCREMENT=3 ; CREATE table t1 ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM AUTO_INCREMENT=3 ;
INSERT INTO t1 VALUES (1, 'aaaaa'); INSERT INTO t1 VALUES (1, 'aaaaa');
INSERT INTO t1 VALUES (3, 'aaaaa'); INSERT INTO t1 VALUES (3, 'aaaaa');
INSERT INTO t1 VALUES (2, 'eeeeeee'); INSERT INTO t1 VALUES (2, 'eeeeeee');
select distinct left(name,1) as name from t1; select distinct left(name,1) as name from t1;
drop table t1; drop table t1;
...@@ -141,7 +141,7 @@ void MYSQL_LOG::init(enum_log_type log_type_arg, ...@@ -141,7 +141,7 @@ void MYSQL_LOG::init(enum_log_type log_type_arg,
io_cache_type = io_cache_type_arg; io_cache_type = io_cache_type_arg;
no_auto_events = no_auto_events_arg; no_auto_events = no_auto_events_arg;
max_size=max_size_arg; max_size=max_size_arg;
DBUG_PRINT("info",("log_type=%d max_size=%lu", log_type, max_size)); DBUG_PRINT("info",("log_type: %d max_size: %lu", log_type, max_size));
if (!inited) if (!inited)
{ {
inited= 1; inited= 1;
...@@ -909,7 +909,7 @@ bool MYSQL_LOG::append(Log_event* ev) ...@@ -909,7 +909,7 @@ bool MYSQL_LOG::append(Log_event* ev)
goto err; goto err;
} }
bytes_written += ev->get_event_len(); bytes_written += ev->get_event_len();
DBUG_PRINT("info",("max_size=%lu",max_size)); DBUG_PRINT("info",("max_size: %lu",max_size));
if ((uint) my_b_append_tell(&log_file) > max_size) if ((uint) my_b_append_tell(&log_file) > max_size)
{ {
pthread_mutex_lock(&LOCK_index); pthread_mutex_lock(&LOCK_index);
...@@ -943,7 +943,7 @@ bool MYSQL_LOG::appendv(const char* buf, uint len,...) ...@@ -943,7 +943,7 @@ bool MYSQL_LOG::appendv(const char* buf, uint len,...)
} }
bytes_written += len; bytes_written += len;
} while ((buf=va_arg(args,const char*)) && (len=va_arg(args,uint))); } while ((buf=va_arg(args,const char*)) && (len=va_arg(args,uint)));
DBUG_PRINT("info",("max_size=%lu",max_size)); DBUG_PRINT("info",("max_size: %lu",max_size));
if ((uint) my_b_append_tell(&log_file) > max_size) if ((uint) my_b_append_tell(&log_file) > max_size)
{ {
pthread_mutex_lock(&LOCK_index); pthread_mutex_lock(&LOCK_index);
...@@ -1206,7 +1206,7 @@ bool MYSQL_LOG::write(Log_event* event_info) ...@@ -1206,7 +1206,7 @@ bool MYSQL_LOG::write(Log_event* event_info)
} }
} }
/* We wrote to the real log, check automatic rotation; */ /* We wrote to the real log, check automatic rotation; */
DBUG_PRINT("info",("max_size=%lu",max_size)); DBUG_PRINT("info",("max_size: %lu",max_size));
should_rotate= (my_b_tell(file) >= (my_off_t) max_size); should_rotate= (my_b_tell(file) >= (my_off_t) max_size);
} }
error=0; error=0;
...@@ -1337,7 +1337,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache) ...@@ -1337,7 +1337,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache)
log_file.pos_in_file))) log_file.pos_in_file)))
goto err; goto err;
signal_update(); signal_update();
DBUG_PRINT("info",("max_size=%lu",max_size)); DBUG_PRINT("info",("max_size: %lu",max_size));
if (my_b_tell(&log_file) >= (my_off_t) max_size) if (my_b_tell(&log_file) >= (my_off_t) max_size)
{ {
pthread_mutex_lock(&LOCK_index); pthread_mutex_lock(&LOCK_index);
......
...@@ -1205,10 +1205,10 @@ int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname) ...@@ -1205,10 +1205,10 @@ int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname)
/* /*
The relay log will now be opened, as a SEQ_READ_APPEND IO_CACHE. It is The relay log will now be opened, as a SEQ_READ_APPEND IO_CACHE. It is
notable that the last kilobytes of it (8 kB for example) may live in memory, notable that the last kilobytes of it (8 kB for example) may live in
not on disk (depending on what the thread using it does). While this is memory, not on disk (depending on what the thread using it does). While
efficient, it has a side-effect one must know: this is efficient, it has a side-effect one must know:
the size of the relay log on disk (displayed by 'ls -l' on Unix) can be a The size of the relay log on disk (displayed by 'ls -l' on Unix) can be a
few kilobytes less than one would expect by doing SHOW SLAVE STATUS; this few kilobytes less than one would expect by doing SHOW SLAVE STATUS; this
happens when only the IO thread is started (not the SQL thread). The happens when only the IO thread is started (not the SQL thread). The
"missing" kilobytes are in memory, are preserved during 'STOP SLAVE; START "missing" kilobytes are in memory, are preserved during 'STOP SLAVE; START
...@@ -1221,23 +1221,19 @@ int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname) ...@@ -1221,23 +1221,19 @@ int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname)
See how 4 is less than 7811 and 8192 is less than 9744. See how 4 is less than 7811 and 8192 is less than 9744.
WARNING: this is risky because the slave can stay like this for a long time; WARNING: this is risky because the slave can stay like this for a long
then if it has a power failure, master.info says the I/O thread has read time; then if it has a power failure, master.info says the I/O thread has
until 9744 while the relay-log contains only until 8192 (the in-memory part read until 9744 while the relay-log contains only until 8192 (the
from 8192 to 9744 has been lost), so the SQL slave thread will miss some in-memory part from 8192 to 9744 has been lost), so the SQL slave thread
events, silently breaking replication. will miss some events, silently breaking replication.
Ideally we would like to flush master.info only when we know that the relay Ideally we would like to flush master.info only when we know that the relay
log has no in-memory tail. log has no in-memory tail.
Note that the above problem may arise only when only the IO thread is Note that the above problem may arise only when only the IO thread is
started, which is unlikely. started, which is unlikely.
*/ */
if (open_log(&rli->relay_log, glob_hostname, opt_relay_logname,
"-relay-bin", opt_relaylog_index_name,
LOG_BIN, 1 /* read_append cache */,
1 /* no auto events */,
/* /*
For the maximum size, we choose max_relay_log_size if it is For the maximum log size, we choose max_relay_log_size if it is
non-zero, max_binlog_size otherwise. If later the user does SET non-zero, max_binlog_size otherwise. If later the user does SET
GLOBAL on one of these variables, fix_max_binlog_size and GLOBAL on one of these variables, fix_max_binlog_size and
fix_max_relay_log_size will reconsider the choice (for example fix_max_relay_log_size will reconsider the choice (for example
...@@ -1245,6 +1241,11 @@ int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname) ...@@ -1245,6 +1241,11 @@ int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname)
switch to using max_binlog_size for the relay log) and update switch to using max_binlog_size for the relay log) and update
rli->relay_log.max_size (and mysql_bin_log.max_size). rli->relay_log.max_size (and mysql_bin_log.max_size).
*/ */
if (open_log(&rli->relay_log, glob_hostname, opt_relay_logname,
"-relay-bin", opt_relaylog_index_name,
LOG_BIN, 1 /* read_append cache */,
1 /* no auto events */,
max_relay_log_size ? max_relay_log_size : max_binlog_size)) max_relay_log_size ? max_relay_log_size : max_binlog_size))
{ {
sql_print_error("Failed in open_log() called from init_relay_log_info()"); sql_print_error("Failed in open_log() called from init_relay_log_info()");
...@@ -3445,23 +3446,25 @@ void rotate_relay_log(MASTER_INFO* mi) ...@@ -3445,23 +3446,25 @@ void rotate_relay_log(MASTER_INFO* mi)
/* If this server is not a slave (or RESET SLAVE has just been run) */ /* If this server is not a slave (or RESET SLAVE has just been run) */
if (!rli->inited) if (!rli->inited)
{ {
DBUG_PRINT("info", ("rli->inited=0")); DBUG_PRINT("info", ("rli->inited == 0"));
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
lock_slave_threads(mi); lock_slave_threads(mi);
pthread_mutex_lock(&rli->data_lock); pthread_mutex_lock(&rli->data_lock);
/* If the relay log is closed, new_file() will do nothing. */ /* If the relay log is closed, new_file() will do nothing. */
rli->relay_log.new_file(1); rli->relay_log.new_file(1);
/* /*
We harvest now, because otherwise BIN_LOG_HEADER_SIZE will not immediately We harvest now, because otherwise BIN_LOG_HEADER_SIZE will not immediately
be counted, so imagine a succession of FLUSH LOGS and assume the slave be counted, so imagine a succession of FLUSH LOGS and assume the slave
threads are started: threads are started:
relay_log_space decreases by the size of the deleted relay log, but does not relay_log_space decreases by the size of the deleted relay log, but does
increase, so flush-after-flush we may become negative, which is wrong. not increase, so flush-after-flush we may become negative, which is wrong.
Even if this will be corrected as soon as a query is replicated on the slave Even if this will be corrected as soon as a query is replicated on the
(because the I/O thread will then call harvest_bytes_written() which will slave (because the I/O thread will then call harvest_bytes_written() which
harvest all these BIN_LOG_HEADER_SIZE we forgot), it may give strange output will harvest all these BIN_LOG_HEADER_SIZE we forgot), it may give strange
in SHOW SLAVE STATUS meanwhile. So we harvest now. output in SHOW SLAVE STATUS meanwhile. So we harvest now.
If the log is closed, then this will just harvest the last writes, probably If the log is closed, then this will just harvest the last writes, probably
0 as they probably have been harvested. 0 as they probably have been harvested.
*/ */
......
...@@ -145,12 +145,15 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, ...@@ -145,12 +145,15 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
else else
{ {
table->file->print_error(error,MYF(0)); table->file->print_error(error,MYF(0));
error=1; /* In < 4.0.14 we set the error number to 0 here, but that /*
In < 4.0.14 we set the error number to 0 here, but that
was not sensible, because then MySQL would not roll back the was not sensible, because then MySQL would not roll back the
failed DELETE, and also wrote it to the binlog. For MyISAM failed DELETE, and also wrote it to the binlog. For MyISAM
tables a DELETE probably never should fail (?), but for tables a DELETE probably never should fail (?), but for
InnoDB it can fail in a FOREIGN KEY error or an InnoDB it can fail in a FOREIGN KEY error or an
out-of-tablespace error. (Comment by Heikki July 7, 2003) */ out-of-tablespace error.
*/
error= 1;
break; break;
} }
} }
......
...@@ -2178,7 +2178,7 @@ mysql_execute_command(void) ...@@ -2178,7 +2178,7 @@ mysql_execute_command(void)
} }
if (check_access(thd,SELECT_ACL,db,&thd->col_access)) if (check_access(thd,SELECT_ACL,db,&thd->col_access))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
if (!thd->col_access && grant_option && check_grant_db(thd,db)) if (!thd->col_access && check_grant_db(thd,db))
{ {
net_printf(&thd->net,ER_DBACCESS_DENIED_ERROR, net_printf(&thd->net,ER_DBACCESS_DENIED_ERROR,
thd->priv_user, thd->priv_user,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment