summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <msvensson@neptunus.(none)>2006-11-24 12:12:25 +0100
committerunknown <msvensson@neptunus.(none)>2006-11-24 12:12:25 +0100
commit87e3047501d74efd55983d6c45936f1bc3a13256 (patch)
tree857a75fef3cd023ca835be3648bb195609b13cdb /sql
parentde9980f4c61c3fdfe7547789ec4b0a86dc49c6a0 (diff)
parent6bd194d7ca9942a5926fe98dd8f59bd5213f24fd (diff)
downloadmariadb-git-87e3047501d74efd55983d6c45936f1bc3a13256.tar.gz
Merge neptunus.(none):/home/msvensson/mysql/mysql-4.1
into neptunus.(none):/home/msvensson/mysql/mysql-4.1-maint mysql-test/Makefile.am: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/t/func_time.test: Auto merged sql-common/my_time.c: Auto merged sql/item_timefunc.cc: Auto merged mysql-test/mysql-test-run-shell.sh: Auto merged mysql-test/mysql-test-run.pl: Manual merge of changes for RPM
Diffstat (limited to 'sql')
-rw-r--r--sql/item_sum.cc20
-rw-r--r--sql/item_timefunc.cc13
-rw-r--r--sql/log_event.h8
-rw-r--r--sql/mysql_priv.h6
-rw-r--r--sql/slave.cc23
-rw-r--r--sql/sql_repl.cc6
-rw-r--r--sql/time.cc9
-rw-r--r--sql/tztime.cc76
8 files changed, 125 insertions, 36 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 5fd65fecbfc..2c8158b35fd 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1673,6 +1673,7 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)),
{
char buff[MAX_FIELD_WIDTH];
String tmp((char *)&buff,sizeof(buff),default_charset_info), tmp2;
+ uint old_length= item->result.length();
if (item->no_appended)
item->no_appended= FALSE;
@@ -1711,8 +1712,22 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)),
/* stop if length of result more than group_concat_max_len */
if (item->result.length() > item->group_concat_max_len)
{
+ int well_formed_error;
+ CHARSET_INFO *cs= item->collation.collation;
+ const char *ptr= item->result.ptr();
+ uint add_length;
+ /*
+ It's ok to use item->result.length() as the fourth argument
+ as this is never used to limit the length of the data.
+ Cut is done with the third argument.
+ */
+ add_length= cs->cset->well_formed_len(cs,
+ ptr + old_length,
+ ptr + item->group_concat_max_len,
+ item->result.length(),
+ &well_formed_error);
+ item->result.length(old_length + add_length);
item->count_cut_values++;
- item->result.length(item->group_concat_max_len);
item->warning_for_row= TRUE;
return 1;
}
@@ -1902,8 +1917,7 @@ bool Item_func_group_concat::add()
we can dump the row here in case of GROUP_CONCAT(DISTINCT...)
instead of doing tree traverse later.
*/
- if (result.length() <= group_concat_max_len &&
- !warning_for_row &&
+ if (!warning_for_row &&
(!tree_mode || (el->count == 1 && distinct && !arg_count_order)))
dump_leaf_key(table->record[0], 1, this);
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 62005e2b65c..d6465406c68 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -1931,15 +1931,10 @@ bool Item_func_convert_tz::get_date(TIME *ltime,
return 1;
}
- /* Check if we in range where we treat datetime values as non-UTC */
- if (ltime->year < TIMESTAMP_MAX_YEAR && ltime->year > TIMESTAMP_MIN_YEAR ||
- ltime->year==TIMESTAMP_MAX_YEAR && ltime->month==1 && ltime->day==1 ||
- ltime->year==TIMESTAMP_MIN_YEAR && ltime->month==12 && ltime->day==31)
- {
- my_time_tmp= from_tz->TIME_to_gmt_sec(ltime, &not_used);
- if (my_time_tmp >= TIMESTAMP_MIN_VALUE && my_time_tmp <= TIMESTAMP_MAX_VALUE)
- to_tz->gmt_sec_to_TIME(ltime, my_time_tmp);
- }
+ my_time_tmp= from_tz->TIME_to_gmt_sec(ltime, &not_used);
+ /* my_time_tmp is guranteed to be in the allowed range */
+ if (my_time_tmp)
+ to_tz->gmt_sec_to_TIME(ltime, my_time_tmp);
null_value= 0;
return 0;
diff --git a/sql/log_event.h b/sql/log_event.h
index 6c4e65f7460..ec2d8993bca 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -148,6 +148,14 @@ struct sql_ex_info
#define DELETE_FILE_HEADER_LEN 4
/*
+ Max number of possible extra bytes in a replication event compared to a
+ packet (i.e. a query) sent from client to master.
+*/
+#define MAX_LOG_EVENT_HEADER (LOG_EVENT_HEADER_LEN + /* write_header */ \
+ QUERY_HEADER_LEN + /* write_data */ \
+ NAME_LEN + 1)
+
+/*
Event header offsets;
these point to places inside the fixed header.
*/
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index b1b0016c06b..8d6cdebe1f7 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -144,12 +144,6 @@ MY_LOCALE *my_locale_by_name(const char *name);
/* Characters shown for the command in 'show processlist' */
#define PROCESS_LIST_WIDTH 100
-/* Time handling defaults */
-#define TIMESTAMP_MAX_YEAR 2038
-#define YY_PART_YEAR 70
-#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
-#define TIMESTAMP_MAX_VALUE 2145916799
-#define TIMESTAMP_MIN_VALUE 1
#define PRECISION_FOR_DOUBLE 53
#define PRECISION_FOR_FLOAT 24
diff --git a/sql/slave.cc b/sql/slave.cc
index e3bc2d75829..6785e92b9f9 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -2618,6 +2618,13 @@ static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type)
SYSTEM_THREAD_SLAVE_SQL : SYSTEM_THREAD_SLAVE_IO;
thd->host_or_ip= "";
my_net_init(&thd->net, 0);
+/*
+ Adding MAX_LOG_EVENT_HEADER_LEN to the max_allowed_packet on all
+ slave threads, since a replication event can become this much larger
+ than the corresponding packet (query) sent from client to master.
+*/
+ thd->variables.max_allowed_packet= global_system_variables.max_allowed_packet
+ + MAX_LOG_EVENT_HEADER; /* note, incr over the global not session var */
thd->net.read_timeout = slave_net_timeout;
thd->master_access= ~(ulong)0;
thd->priv_user = 0;
@@ -3143,16 +3150,24 @@ slave_begin:
sql_print_error("Slave I/O thread: error in mysql_init()");
goto err;
}
-
+
thd->proc_info = "Connecting to master";
// we can get killed during safe_connect
if (!safe_connect(thd, mysql, mi))
+ {
sql_print_information("Slave I/O thread: connected to master '%s@%s:%d',\
replication started in log '%s' at position %s", mi->user,
- mi->host, mi->port,
- IO_RPL_LOG_NAME,
- llstr(mi->master_log_pos,llbuff));
+ mi->host, mi->port,
+ IO_RPL_LOG_NAME,
+ llstr(mi->master_log_pos,llbuff));
+ /*
+ Adding MAX_LOG_EVENT_HEADER_LEN to the max_packet_size on the I/O
+ thread, since a replication event can become this much larger than
+ the corresponding packet (query) sent from client to master.
+ */
+ mysql->net.max_packet_size= thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER;
+ }
else
{
sql_print_error("Slave I/O thread killed while connecting to master");
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 2a7ab55b8c4..a20f2a6506c 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -420,6 +420,12 @@ impossible position";
goto err;
}
packet->set("\0", 1, &my_charset_bin);
+ /*
+ Adding MAX_LOG_EVENT_HEADER_LEN, since a binlog event can become
+ this larger than the corresponding packet (query) sent
+ from client to master.
+ */
+ thd->variables.max_allowed_packet+= MAX_LOG_EVENT_HEADER;
while (!net->error && net->vio != 0 && !thd->killed)
{
diff --git a/sql/time.cc b/sql/time.cc
index ddc5e6435be..a1a27619e4b 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -230,14 +230,11 @@ my_time_t TIME_to_timestamp(THD *thd, const TIME *t, bool *in_dst_time_gap)
*in_dst_time_gap= 0;
- if (t->year < TIMESTAMP_MAX_YEAR && t->year > TIMESTAMP_MIN_YEAR ||
- t->year == TIMESTAMP_MAX_YEAR && t->month == 1 && t->day == 1 ||
- t->year == TIMESTAMP_MIN_YEAR && t->month == 12 && t->day == 31)
+ timestamp= thd->variables.time_zone->TIME_to_gmt_sec(t, in_dst_time_gap);
+ if (timestamp)
{
thd->time_zone_used= 1;
- timestamp= thd->variables.time_zone->TIME_to_gmt_sec(t, in_dst_time_gap);
- if (timestamp >= TIMESTAMP_MIN_VALUE && timestamp <= TIMESTAMP_MAX_VALUE)
- return timestamp;
+ return timestamp;
}
/* If we are here we have range error. */
diff --git a/sql/tztime.cc b/sql/tztime.cc
index b0a32748998..9af33526c98 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -885,9 +885,14 @@ TIME_to_gmt_sec(const TIME *t, const TIME_ZONE_INFO *sp, bool *in_dst_time_gap)
my_time_t local_t;
uint saved_seconds;
uint i;
+ int shift= 0;
DBUG_ENTER("TIME_to_gmt_sec");
+ if (!validate_timestamp_range(t))
+ DBUG_RETURN(0);
+
+
/* We need this for correct leap seconds handling */
if (t->second < SECS_PER_MIN)
saved_seconds= 0;
@@ -895,11 +900,29 @@ TIME_to_gmt_sec(const TIME *t, const TIME_ZONE_INFO *sp, bool *in_dst_time_gap)
saved_seconds= t->second;
/*
- NOTE If we want to convert full my_time_t range without MySQL
- restrictions we should catch overflow here somehow.
+ NOTE: to convert full my_time_t range we do a shift of the
+ boundary dates here to avoid overflow of my_time_t.
+ We use alike approach in my_system_gmt_sec().
+
+ However in that function we also have to take into account
+ overflow near 0 on some platforms. That's because my_system_gmt_sec
+ uses localtime_r(), which doesn't work with negative values correctly
+ on platforms with unsigned time_t (QNX). Here we don't use localtime()
+ => we negative values of local_t are ok.
*/
- local_t= sec_since_epoch(t->year, t->month, t->day,
+ if ((t->year == TIMESTAMP_MAX_YEAR) && (t->month == 1) && t->day > 4)
+ {
+ /*
+ We will pass (t->day - shift) to sec_since_epoch(), and
+ want this value to be a positive number, so we shift
+ only dates > 4.01.2038 (to avoid owerflow).
+ */
+ shift= 2;
+ }
+
+
+ local_t= sec_since_epoch(t->year, t->month, (t->day - shift),
t->hour, t->minute,
saved_seconds ? 0 : t->second);
@@ -918,6 +941,22 @@ TIME_to_gmt_sec(const TIME *t, const TIME_ZONE_INFO *sp, bool *in_dst_time_gap)
/* binary search for our range */
i= find_time_range(local_t, sp->revts, sp->revcnt);
+ /*
+ As there are no offset switches at the end of TIMESTAMP range,
+ we could simply check for overflow here (and don't need to bother
+ about DST gaps etc)
+ */
+ if (shift)
+ {
+ if (local_t > (TIMESTAMP_MAX_VALUE - shift*86400L +
+ sp->revtis[i].rt_offset - saved_seconds))
+ {
+ DBUG_RETURN(0); /* my_time_t overflow */
+ }
+ else
+ local_t+= shift*86400L;
+ }
+
if (sp->revtis[i].rt_type)
{
/*
@@ -927,10 +966,16 @@ TIME_to_gmt_sec(const TIME *t, const TIME_ZONE_INFO *sp, bool *in_dst_time_gap)
beginning of the gap.
*/
*in_dst_time_gap= 1;
- DBUG_RETURN(sp->revts[i] - sp->revtis[i].rt_offset + saved_seconds);
+ local_t= sp->revts[i] - sp->revtis[i].rt_offset + saved_seconds;
}
else
- DBUG_RETURN(local_t - sp->revtis[i].rt_offset + saved_seconds);
+ local_t= local_t - sp->revtis[i].rt_offset + saved_seconds;
+
+ /* check for TIMESTAMP_MAX_VALUE was already done above */
+ if (local_t < TIMESTAMP_MIN_VALUE)
+ local_t= 0;
+
+ DBUG_RETURN(local_t);
}
@@ -1294,9 +1339,24 @@ Time_zone_offset::Time_zone_offset(long tz_offset_arg):
my_time_t
Time_zone_offset::TIME_to_gmt_sec(const TIME *t, bool *in_dst_time_gap) const
{
- return sec_since_epoch(t->year, t->month, t->day,
- t->hour, t->minute, t->second) -
- offset;
+ my_time_t local_t;
+
+ /*
+ Check timestamp range.we have to do this as calling function relies on
+ us to make all validation checks here.
+ */
+ if (!validate_timestamp_range(t))
+ return 0;
+
+ local_t= sec_since_epoch(t->year, t->month, t->day,
+ t->hour, t->minute, t->second) -
+ offset;
+
+ if (local_t >= TIMESTAMP_MIN_VALUE && local_t <= TIMESTAMP_MAX_VALUE)
+ return local_t;
+
+ /* range error*/
+ return 0;
}