Skip to content

Commit 22644b5

Browse files
author
brian@zim.(none)
committed
Merge baker@bk-internal.mysql.com:/home/bk/mysql-5.0
into zim.(none):/home/brian/mysql/mysql-5.0
2 parents da60b60 + 0eacb6f commit 22644b5

File tree

7 files changed

+142
-69
lines changed

7 files changed

+142
-69
lines changed

Makefile.am

+20-21
Original file line numberDiff line numberDiff line change
@@ -97,36 +97,35 @@ tags:
9797
support-files/build-tags
9898
.PHONY: init-db bin-dist
9999

100-
# Test installation. Ports are configurable from the environment.
101-
102-
MYSQL_TEST_MANAGER_PORT = 9305
103-
MYSQL_TEST_MASTER_PORT = 9306
104-
MYSQL_TEST_SLAVE_PORT = 9308
105-
MYSQL_TEST_NDB_PORT = 9350
106-
MYSQL_TEST_RUN_ARGS = --manager-port=$(MYSQL_TEST_MANAGER_PORT) \
107-
--master_port=$(MYSQL_TEST_MASTER_PORT) \
108-
--slave_port=$(MYSQL_TEST_SLAVE_PORT) \
109-
--ndbcluster_port=$(MYSQL_TEST_NDB_PORT)
100+
# Target 'test' will run the regression test suite using the built server.
101+
#
102+
# If you are running in a shared environment, users can avoid clashing
103+
# port numbers by setting individual small numbers 1-100 to the
104+
# environment variable MTR_BUILD_THREAD. The script "mysql-test-run"
105+
# will then calculate the various port numbers it needs from this,
106+
# making sure each user use different ports.
110107

111108
test:
112109
cd mysql-test ; \
113-
./mysql-test-run $(MYSQL_TEST_RUN_ARGS) && \
114-
./mysql-test-run $(MYSQL_TEST_RUN_ARGS) --ps-protocol
110+
./mysql-test-run && \
111+
./mysql-test-run --ps-protocol
115112

116113
test-force:
117-
cd mysql-test ; \
118-
./mysql-test-run $(MYSQL_TEST_RUN_ARGS) --force ; \
119-
./mysql-test-run $(MYSQL_TEST_RUN_ARGS) --ps-protocol --force
114+
cd mysql-test; \
115+
./mysql-test-run --force ; \
116+
./mysql-test-run --ps-protocol --force
120117

118+
# We are testing a new Perl version of the test script
121119
test-pl:
122-
cd mysql-test ; \
123-
./mysql-test-run.pl $(MYSQL_TEST_RUN_ARGS) && \
124-
./mysql-test-run.pl $(MYSQL_TEST_RUN_ARGS) --ps-protocol
120+
cd mysql-test; \
121+
./mysql-test-run.pl && \
122+
./mysql-test-run.pl --ps-protocol
125123

126124
test-force-pl:
127-
cd mysql-test ; \
128-
./mysql-test-run.pl $(MYSQL_TEST_RUN_ARGS) --force ; \
129-
./mysql-test-run.pl $(MYSQL_TEST_RUN_ARGS) --ps-protocol --force
125+
cd mysql-test; \
126+
./mysql-test-run.pl --force ; \
127+
./mysql-test-run.pl --ps-protocol --force
130128

131129
# Don't update the files from bitkeeper
132130
%::SCCS/s.%
131+

include/my_pthread.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#endif
2626

2727
#ifdef __cplusplus
28-
#define EXTERN_C extern "C"
28+
#define EXTERNC extern "C"
2929
extern "C" {
3030
#else
31-
#define EXTERN_C
31+
#define EXTERNC
3232
#endif /* __cplusplus */
3333

3434
#if defined(__WIN__) || defined(OS2)
@@ -80,10 +80,10 @@ struct timespec { /* For pthread_cond_timedwait() */
8080
typedef int pthread_mutexattr_t;
8181
#define win_pthread_self my_thread_var->pthread_self
8282
#ifdef OS2
83-
#define pthread_handler_t EXTERN_C void * _Optlink
83+
#define pthread_handler_t EXTERNC void * _Optlink
8484
typedef void * (_Optlink *pthread_handler)(void *);
8585
#else
86-
#define pthread_handler_t EXTERN_C void * __cdecl
86+
#define pthread_handler_t EXTERNC void * __cdecl
8787
typedef void * (__cdecl *pthread_handler)(void *);
8888
#endif
8989

@@ -187,7 +187,7 @@ typedef int pthread_attr_t; /* Needed by Unixware 7.0.0 */
187187
#define pthread_key_create(A,B) thr_keycreate((A),(B))
188188
#define pthread_key_delete(A) thr_keydelete(A)
189189

190-
#define pthread_handler_t EXTERN_C void *
190+
#define pthread_handler_t EXTERNC void *
191191
#define pthread_key(T,V) pthread_key_t V
192192

193193
void * my_pthread_getspecific_imp(pthread_key_t key);
@@ -265,7 +265,7 @@ extern int my_pthread_getprio(pthread_t thread_id);
265265
#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,(V))
266266
#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,(void*) (V))
267267
#define pthread_detach_this_thread()
268-
#define pthread_handler_t EXTERN_C void *
268+
#define pthread_handler_t EXTERNC void *
269269
typedef void *(* pthread_handler)(void *);
270270

271271
/* Test first for RTS or FSU threads */

mysql-test/mysql-test-run.sh

+19
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,25 @@ NDBCLUSTER_PORT=9350
216216
MYSQL_MANAGER_PW_FILE=$MYSQL_TEST_DIR/var/tmp/manager.pwd
217217
MYSQL_MANAGER_LOG=$MYSQL_TEST_DIR/var/log/manager.log
218218
MYSQL_MANAGER_USER=root
219+
220+
#
221+
# To make it easier for different devs to work on the same host,
222+
# an environment variable can be used to control all ports. A small
223+
# number is to be used, 0 - 16 or similar.
224+
#
225+
if [ -n "$MTR_BUILD_THREAD" ] ; then
226+
MASTER_MYPORT=`expr $MTR_BUILD_THREAD '*' 40 + 8120`
227+
MYSQL_MANAGER_PORT=`expr $MASTER_MYPORT + 2`
228+
SLAVE_MYPORT=`expr $MASTER_MYPORT + 16`
229+
NDBCLUSTER_PORT=`expr $MASTER_MYPORT + 24`
230+
231+
echo "Using MTR_BUILD_THREAD = $MTR_BUILD_THREAD"
232+
echo "Using MASTER_MYPORT = $MASTER_MYPORT"
233+
echo "Using MYSQL_MANAGER_PORT = $MYSQL_MANAGER_PORT"
234+
echo "Using SLAVE_MYPORT = $SLAVE_MYPORT"
235+
echo "Using NDBCLUSTER_PORT = $NDBCLUSTER_PORT"
236+
fi
237+
219238
NO_SLAVE=0
220239
USER_TEST=
221240
FAILED_CASES=

mysql-test/r/func_time.result

+51
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,54 @@ call t_sysdate();
760760
@a != @b
761761
1
762762
drop procedure t_sysdate;
763+
select timestampdiff(month,'2004-09-11','2004-09-11');
764+
timestampdiff(month,'2004-09-11','2004-09-11')
765+
0
766+
select timestampdiff(month,'2004-09-11','2005-09-11');
767+
timestampdiff(month,'2004-09-11','2005-09-11')
768+
12
769+
select timestampdiff(month,'2004-09-11','2006-09-11');
770+
timestampdiff(month,'2004-09-11','2006-09-11')
771+
24
772+
select timestampdiff(month,'2004-09-11','2007-09-11');
773+
timestampdiff(month,'2004-09-11','2007-09-11')
774+
36
775+
select timestampdiff(month,'2005-09-11','2004-09-11');
776+
timestampdiff(month,'2005-09-11','2004-09-11')
777+
-12
778+
select timestampdiff(month,'2005-09-11','2003-09-11');
779+
timestampdiff(month,'2005-09-11','2003-09-11')
780+
-24
781+
select timestampdiff(month,'2004-02-28','2005-02-28');
782+
timestampdiff(month,'2004-02-28','2005-02-28')
783+
12
784+
select timestampdiff(month,'2004-02-29','2005-02-28');
785+
timestampdiff(month,'2004-02-29','2005-02-28')
786+
11
787+
select timestampdiff(month,'2004-02-28','2005-02-28');
788+
timestampdiff(month,'2004-02-28','2005-02-28')
789+
12
790+
select timestampdiff(month,'2004-03-29','2005-03-28');
791+
timestampdiff(month,'2004-03-29','2005-03-28')
792+
11
793+
select timestampdiff(month,'2003-02-28','2004-02-29');
794+
timestampdiff(month,'2003-02-28','2004-02-29')
795+
12
796+
select timestampdiff(month,'2003-02-28','2005-02-28');
797+
timestampdiff(month,'2003-02-28','2005-02-28')
798+
24
799+
select timestampdiff(month,'1999-09-11','2001-10-10');
800+
timestampdiff(month,'1999-09-11','2001-10-10')
801+
24
802+
select timestampdiff(month,'1999-09-11','2001-9-11');
803+
timestampdiff(month,'1999-09-11','2001-9-11')
804+
24
805+
select timestampdiff(year,'1999-09-11','2001-9-11');
806+
timestampdiff(year,'1999-09-11','2001-9-11')
807+
2
808+
select timestampdiff(year,'2004-02-28','2005-02-28');
809+
timestampdiff(year,'2004-02-28','2005-02-28')
810+
1
811+
select timestampdiff(year,'2004-02-29','2005-02-28');
812+
timestampdiff(year,'2004-02-29','2005-02-28')
813+
0

mysql-test/t/func_time.test

+24
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,28 @@ delimiter ;//
404404
call t_sysdate();
405405
drop procedure t_sysdate;
406406

407+
#
408+
# Bug #13534: timestampdiff() returned incorrect results across leap years
409+
#
410+
select timestampdiff(month,'2004-09-11','2004-09-11');
411+
select timestampdiff(month,'2004-09-11','2005-09-11');
412+
select timestampdiff(month,'2004-09-11','2006-09-11');
413+
select timestampdiff(month,'2004-09-11','2007-09-11');
414+
select timestampdiff(month,'2005-09-11','2004-09-11');
415+
select timestampdiff(month,'2005-09-11','2003-09-11');
416+
417+
select timestampdiff(month,'2004-02-28','2005-02-28');
418+
select timestampdiff(month,'2004-02-29','2005-02-28');
419+
select timestampdiff(month,'2004-02-28','2005-02-28');
420+
select timestampdiff(month,'2004-03-29','2005-03-28');
421+
select timestampdiff(month,'2003-02-28','2004-02-29');
422+
select timestampdiff(month,'2003-02-28','2005-02-28');
423+
424+
select timestampdiff(month,'1999-09-11','2001-10-10');
425+
select timestampdiff(month,'1999-09-11','2001-9-11');
426+
427+
select timestampdiff(year,'1999-09-11','2001-9-11');
428+
select timestampdiff(year,'2004-02-28','2005-02-28');
429+
select timestampdiff(year,'2004-02-29','2005-02-28');
430+
407431
# End of 5.0 tests

sql/item_timefunc.cc

+21-42
Original file line numberDiff line numberDiff line change
@@ -2723,70 +2723,49 @@ longlong Item_func_timestamp_diff::val_int()
27232723
int_type == INTERVAL_QUARTER ||
27242724
int_type == INTERVAL_MONTH)
27252725
{
2726-
uint year;
2727-
uint year_beg, year_end, month_beg, month_end;
2728-
uint diff_days= (uint) (seconds/86400L);
2729-
uint diff_years= 0;
2726+
uint year_beg, year_end, month_beg, month_end, day_beg, day_end;
2727+
uint years= 0;
27302728
if (neg == -1)
27312729
{
27322730
year_beg= ltime2.year;
27332731
year_end= ltime1.year;
27342732
month_beg= ltime2.month;
27352733
month_end= ltime1.month;
2734+
day_beg= ltime2.day;
2735+
day_end= ltime1.day;
27362736
}
27372737
else
27382738
{
27392739
year_beg= ltime1.year;
27402740
year_end= ltime2.year;
27412741
month_beg= ltime1.month;
27422742
month_end= ltime2.month;
2743-
}
2744-
/* calc years*/
2745-
for (year= year_beg;year < year_end; year++)
2746-
{
2747-
uint days=calc_days_in_year(year);
2748-
if (days > diff_days)
2749-
break;
2750-
diff_days-= days;
2751-
diff_years++;
2743+
day_beg= ltime1.day;
2744+
day_end= ltime2.day;
27522745
}
27532746

2754-
/* calc months; Current year is in the 'year' variable */
2755-
month_beg--; /* Change months to be 0-11 for easier calculation */
2756-
month_end--;
2747+
/* calc years */
2748+
years= year_end - year_beg;
2749+
if (month_end < month_beg || (month_end == month_beg && day_end < day_beg))
2750+
years-= 1;
27572751

2758-
months= 12*diff_years;
2759-
while (month_beg != month_end)
2760-
{
2761-
uint m_days= (uint) days_in_month[month_beg];
2762-
if (month_beg == 1)
2763-
{
2764-
/* This is only calculated once so there is no reason to cache it*/
2765-
uint leap= (uint) ((year & 3) == 0 && (year%100 ||
2766-
(year%400 == 0 && year)));
2767-
m_days+= leap;
2768-
}
2769-
if (m_days > diff_days)
2770-
break;
2771-
diff_days-= m_days;
2772-
months++;
2773-
if (month_beg++ == 11) /* if we wrap to next year */
2774-
{
2775-
month_beg= 0;
2776-
year++;
2777-
}
2778-
}
2779-
if (neg == -1)
2780-
months= -months;
2752+
/* calc months */
2753+
months= 12*years;
2754+
if (month_end < month_beg || (month_end == month_beg && day_end < day_beg))
2755+
months+= 12 - (month_beg - month_end);
2756+
else
2757+
months+= (month_end - month_beg);
2758+
if (day_end < day_beg)
2759+
months-= 1;
27812760
}
27822761

27832762
switch (int_type) {
27842763
case INTERVAL_YEAR:
2785-
return months/12;
2764+
return months/12*neg;
27862765
case INTERVAL_QUARTER:
2787-
return months/3;
2766+
return months/3*neg;
27882767
case INTERVAL_MONTH:
2789-
return months;
2768+
return months*neg;
27902769
case INTERVAL_WEEK:
27912770
return seconds/86400L/7L*neg;
27922771
case INTERVAL_DAY:

sql/mysqld.cc

+1
Original file line numberDiff line numberDiff line change
@@ -7155,6 +7155,7 @@ static void fix_paths(void)
71557155
CHARSET_DIR, NullS);
71567156
}
71577157
(void) my_load_path(mysql_charsets_dir, mysql_charsets_dir, buff);
7158+
convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NullS);
71587159
charsets_dir=mysql_charsets_dir;
71597160

71607161
if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir))

0 commit comments

Comments
 (0)