5.1.34_to_7.0.dif

Developed In: C++ — Contributed by: Magnus

Diff between MySQL Server 5.1.34 and MySQL Cluster 7.0 2009-06-04


Magnus
C++
  1.  
  2. client/CMakeLists.txt | 16
  3. client/mysql.cc | 8
  4. client/mysqladmin.cc | 8
  5. client/mysqlbinlog.cc | 8
  6. client/mysqlcheck.c | 8
  7. client/mysqldump.c | 8
  8. client/mysqlimport.c | 6
  9. client/mysqlshow.c | 8
  10. client/mysqltest.cc | 174 ++++-
  11. dbug/dbug.c | 5
  12. include/config-win.h | 38 +
  13. include/m_string.h | 4
  14. include/my_base.h | 16
  15. include/my_global.h | 24
  16. include/my_pthread.h | 108 ++-
  17. include/mysql.h | 11
  18. include/mysql.h.pp | 47 -
  19. include/mysql_com.h | 55 -
  20. include/violite.h | 19
  21. libmysql/manager.c | 5
  22. libmysqld/CMakeLists.txt | 31
  23. mysys/my_bitmap.c | 20
  24. mysys/my_thr_init.c | 24
  25. mysys/my_winthread.c | 72 +-
  26. mysys/queues.c | 14
  27. scripts/mysql_config.sh | 3
  28. sql-common/client.c | 218 ++++--
  29. sql/CMakeLists.txt | 9
  30. sql/field.cc | 13
  31. sql/field.h | 37 +
  32. sql/ha_partition.cc | 124 +--
  33. sql/ha_partition.h | 25
  34. sql/handler.cc | 94 ++
  35. sql/handler.h | 320 +++++++--
  36. sql/hostname.cc | 195 ++---
  37. sql/item_func.cc | 8
  38. sql/lex.h | 5
  39. sql/log.cc | 51 +
  40. sql/log_event.cc | 53 +
  41. sql/log_event.h | 58 +
  42. sql/mysql_priv.h | 40 -
  43. sql/mysqld.cc | 401 +++++++----
  44. sql/net_serv.cc | 12
  45. sql/rpl_mi.cc | 56 +
  46. sql/rpl_mi.h | 6
  47. sql/set_var.cc | 35 -
  48. sql/slave.cc | 186 ++++-
  49. sql/slave.h | 12
  50. sql/sql_base.cc | 67 +
  51. sql/sql_bitmap.h | 58 +
  52. sql/sql_class.cc | 20
  53. sql/sql_class.h | 10
  54. sql/sql_connect.cc | 26
  55. sql/sql_db.cc | 9
  56. sql/sql_delete.cc | 38 -
  57. sql/sql_lex.h | 69 +-
  58. sql/sql_parse.cc | 8
  59. sql/sql_partition.cc | 213 +++---
  60. sql/sql_rename.cc | 8
  61. sql/sql_repl.cc | 191 +++++
  62. sql/sql_show.cc | 96 ++
  63. sql/sql_table.cc | 1609 +++++++++++++++++++++++++++--------------------
  64. sql/sql_update.cc | 45 +
  65. sql/sql_yacc.yy | 251 +++++--
  66. sql/structs.h | 8
  67. sql/table.cc | 131 ++-
  68. sql/table.h | 6
  69. sql/unireg.cc | 50 +
  70. sql/unireg.h | 7
  71. strings/longlong2str.c | 10
  72. strings/my_vsnprintf.c | 110 ++-
  73. unittest/unit.pl | 15
  74. vio/vio.c | 30
  75. vio/viosocket.c | 136 ++-
  76. vio/viossl.c | 18
  77. win/configure.js | 8
  78. zlib/inflate.h | 5
  79. 77 files changed, 4082 insertions(+), 1868 deletions(-)
  80.  
  81. --
  82.  
  83. Showing diff between 5.1.34 and 7.0
  84. --- 5.1.34/mysys/my_bitmap.c 2009-06-03 23:17:32.000000000 +0200
  85. +++ 7.0/mysys/my_bitmap.c 2009-06-04 10:35:49.000000000 +0200
  86. @@ -763,7 +766,7 @@
  87. return (rand() % bitsize);
  88. }
  89.  
  90. -bool test_set_get_clear_bit(MY_BITMAP *map, uint bitsize)
  91. +my_bool test_set_get_clear_bit(MY_BITMAP *map, uint bitsize)
  92. {
  93. uint i, test_bit;
  94. uint no_loops= bitsize > 128 ? 128 : bitsize;
  95. @@ -786,7 +789,7 @@
  96. return TRUE;
  97. }
  98.  
  99. -bool test_flip_bit(MY_BITMAP *map, uint bitsize)
  100. +my_bool test_flip_bit(MY_BITMAP *map, uint bitsize)
  101. {
  102. uint i, test_bit;
  103. uint no_loops= bitsize > 128 ? 128 : bitsize;
  104. @@ -809,13 +812,13 @@
  105. return TRUE;
  106. }
  107.  
  108. -bool test_operators(MY_BITMAP *map __attribute__((unused)),
  109. +my_bool test_operators(MY_BITMAP *map __attribute__((unused)),
  110. uint bitsize __attribute__((unused)))
  111. {
  112. return FALSE;
  113. }
  114.  
  115. -bool test_get_all_bits(MY_BITMAP *map, uint bitsize)
  116. +my_bool test_get_all_bits(MY_BITMAP *map, uint bitsize)
  117. {
  118. uint i;
  119. bitmap_set_all(map);
  120. @@ -857,7 +860,7 @@
  121. return TRUE;
  122. }
  123.  
  124. -bool test_compare_operators(MY_BITMAP *map, uint bitsize)
  125. +my_bool test_compare_operators(MY_BITMAP *map, uint bitsize)
  126. {
  127. uint i, j, test_bit1, test_bit2, test_bit3,test_bit4;
  128. uint no_loops= bitsize > 128 ? 128 : bitsize;
  129. @@ -963,7 +966,7 @@
  130. return TRUE;
  131. }
  132.  
  133. -bool test_count_bits_set(MY_BITMAP *map, uint bitsize)
  134. +my_bool test_count_bits_set(MY_BITMAP *map, uint bitsize)
  135. {
  136. uint i, bit_count=0, test_bit;
  137. uint no_loops= bitsize > 128 ? 128 : bitsize;
  138. @@ -989,7 +992,7 @@
  139. return TRUE;
  140. }
  141.  
  142. -bool test_get_first_bit(MY_BITMAP *map, uint bitsize)
  143. +my_bool test_get_first_bit(MY_BITMAP *map, uint bitsize)
  144. {
  145. uint i, test_bit;
  146. uint no_loops= bitsize > 128 ? 128 : bitsize;
  147. @@ -1014,7 +1017,7 @@
  148. return TRUE;
  149. }
  150.  
  151. -bool test_get_next_bit(MY_BITMAP *map, uint bitsize)
  152. +my_bool test_get_next_bit(MY_BITMAP *map, uint bitsize)
  153. {
  154. uint i, j, test_bit;
  155. uint no_loops= bitsize > 128 ? 128 : bitsize;
  156. @@ -1033,7 +1036,7 @@
  157. return TRUE;
  158. }
  159.  
  160. -bool test_prefix(MY_BITMAP *map, uint bitsize)
  161. +my_bool test_prefix(MY_BITMAP *map, uint bitsize)
  162. {
  163. uint i, j, test_bit;
  164. uint no_loops= bitsize > 128 ? 128 : bitsize;
  165. @@ -1068,7 +1071,7 @@
  166. }
  167.  
  168.  
  169. -bool do_test(uint bitsize)
  170. +my_bool do_test(uint bitsize)
  171. {
  172. MY_BITMAP map;
  173. my_bitmap_map buf[1024];
  174. --- 5.1.34/mysys/my_thr_init.c 2009-06-03 23:17:32.000000000 +0200
  175. +++ 7.0/mysys/my_thr_init.c 2009-06-04 10:35:49.000000000 +0200
  176. @@ -23,11 +26,7 @@
  177. #include <signal.h>
  178.  
  179. #ifdef THREAD
  180. -#ifdef USE_TLS
  181. pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
  182. -#else
  183. -pthread_key(struct st_my_thread_var, THR_KEY_mysys);
  184. -#endif /* USE_TLS */
  185. pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,
  186. THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap,
  187. THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads, THR_LOCK_time;
  188. @@ -258,7 +257,6 @@
  189. (ulong) pthread_self());
  190. #endif
  191.  
  192. -#if !defined(__WIN__) || defined(USE_TLS)
  193. if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys))
  194. {
  195. #ifdef EXTRA_DEBUG_THREADS
  196. @@ -273,20 +271,7 @@
  197. goto end;
  198. }
  199. pthread_setspecific(THR_KEY_mysys,tmp);
  200. -
  201. -#else /* defined(__WIN__) && !(defined(USE_TLS) */
  202. - /*
  203. - Skip initialization if the thread specific variable is already initialized
  204. - */
  205. - if (THR_KEY_mysys.id)
  206. - goto end;
  207. - tmp= &THR_KEY_mysys;
  208. -#endif
  209. -#if defined(__WIN__) && defined(EMBEDDED_LIBRARY)
  210. - tmp->pthread_self= (pthread_t) getpid();
  211. -#else
  212. tmp->pthread_self= pthread_self();
  213. -#endif
  214. pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST);
  215. pthread_cond_init(&tmp->suspend, NULL);
  216. tmp->init= 1;
  217. @@ -342,11 +327,7 @@
  218. pthread_cond_destroy(&tmp->suspend);
  219. #endif
  220. pthread_mutex_destroy(&tmp->mutex);
  221. -#if !defined(__WIN__) || defined(USE_TLS)
  222. free(tmp);
  223. -#else
  224. - tmp->init= 0;
  225. -#endif
  226.  
  227. /*
  228.   Decrement counter for number of running threads. We are using this
  229. @@ -361,9 +342,7 @@
  230.   pthread_mutex_unlock(&THR_LOCK_threads);
  231.   }
  232.   /* The following free has to be done, even if my_thread_var() is 0 */
  233. -#if !defined(__WIN__) || defined(USE_TLS)
  234. pthread_setspecific(THR_KEY_mysys,0);
  235. -#endif
  236. }
  237.  
  238. struct st_my_thread_var *_my_thread_var(void)
  239. --- 5.1.34/mysys/my_winthread.c 2009-06-03 23:17:32.000000000 +0200
  240. +++ 7.0/mysys/my_winthread.c 2009-06-04 10:35:49.000000000 +0200
  241. @@ -47,8 +50,7 @@
  242. @retval 0 Mutex was acquired
  243. @retval EBUSY Mutex was already locked by a thread
  244. */
  245. -int
  246. -win_pthread_mutex_trylock(pthread_mutex_t *mutex)
  247. +int pthread_mutex_trylock(pthread_mutex_t *mutex)
  248. {
  249. if (TryEnterCriticalSection(mutex))
  250. {
  251. @@ -73,20 +75,37 @@
  252. ** in the new thread.
  253. */
  254.  
  255. -pthread_handler_t pthread_start(void *param)
  256. +pthread_handler_t pstart(void *param);
  257. +
  258. +pthread_key_t detached;
  259. +
  260. +unsigned int __stdcall joinable_pstart(void*p)
  261. +{
  262. + pthread_setspecific(detached,0);
  263. +
  264. + return (unsigned int)pstart(p);
  265. +}
  266. +
  267. +void __cdecl detached_pstart(void*p)
  268. +{
  269. + pthread_setspecific(detached,(void*)1);
  270. +
  271. + pstart(p);
  272. +}
  273. +
  274. +pthread_handler_t pstart(void *param)
  275. {
  276. pthread_handler func=((struct pthread_map *) param)->func;
  277. void *func_param=((struct pthread_map *) param)->param;
  278. my_thread_init(); /* Will always succeed in windows */
  279. pthread_mutex_lock(&THR_LOCK_thread); /* Wait for beginthread to return */
  280. - win_pthread_self=((struct pthread_map *) param)->pthreadself;
  281. + my_thread_var->pthread_self=((struct pthread_map *) param)->pthreadself;
  282. pthread_mutex_unlock(&THR_LOCK_thread);
  283. free((char*) param); /* Free param from create */
  284. pthread_exit((void*) (*func)(func_param));
  285. return 0; /* Safety */
  286. }
  287.  
  288. -
  289. int pthread_create(pthread_t *thread_id, pthread_attr_t *attr,
  290. pthread_handler func, void *param)
  291. {
  292. @@ -99,15 +118,19 @@
  293. map->func=func;
  294. map->param=param;
  295. pthread_mutex_lock(&THR_LOCK_thread);
  296. -#ifdef __BORLANDC__
  297. - hThread=(HANDLE)_beginthread((void(_USERENTRY *)(void *)) pthread_start,
  298. - attr->dwStackSize ? attr->dwStackSize :
  299. - 65535, (void*) map);
  300. +#ifdef __BORLANDC__
  301. +#define BC_CAST (void(_USERENTRY *)(void *))
  302. #else
  303. - hThread=(HANDLE)_beginthread((void( __cdecl *)(void *)) pthread_start,
  304. - attr->dwStackSize ? attr->dwStackSize :
  305. - 65535, (void*) map);
  306. +#define BC_CAST
  307. #endif
  308. + {
  309. + unsigned ss=attr->dwStackSize ? attr->dwStackSize : 65535;
  310. + pthread_key_create(&detached,0);
  311. + if (attr->detached)
  312. + hThread=(HANDLE)_beginthread(BC_CAST detached_pstart,ss,(void*)map);
  313. + else
  314. + hThread=(HANDLE)_beginthreadex(NULL,ss,joinable_pstart,(void*)map,0,0);
  315. + }
  316. DBUG_PRINT("info", ("hThread=%lu",(long) hThread));
  317. *thread_id=map->pthreadself=hThread;
  318. pthread_mutex_unlock(&THR_LOCK_thread);
  319. @@ -126,15 +149,31 @@
  320.  
  321. void pthread_exit(void *a)
  322. {
  323. - _endthread();
  324. + if(pthread_getspecific(detached))
  325. + _endthread();
  326. + else
  327. + _endthreadex((unsigned)a);
  328. }
  329.  
  330. -/* This is neaded to get the macro pthread_setspecific to work */
  331. -
  332. -int win_pthread_setspecific(void *a,void *b,uint length)
  333. +int pthread_join(pthread_t thread, void **value_ptr)
  334. {
  335. - memcpy(a,b,length);
  336. - return 0;
  337. + DWORD dw=0,
  338. + wfso=WaitForSingleObject(thread, INFINITE);
  339. + if(wfso == WAIT_OBJECT_0)
  340. + {
  341. + if(!GetExitCodeThread(thread, &dw))
  342. + {
  343. + DWORD e=GetLastError();
  344. + return -2;
  345. + }
  346. + else
  347. + {
  348. + if(value_ptr)*value_ptr=(void*)dw;
  349. + CloseHandle(thread);
  350. + return 0;
  351. + }
  352. + }
  353. + return -1;
  354. }
  355.  
  356. #endif
  357. --- 5.1.34/mysys/queues.c 2009-06-03 23:17:32.000000000 +0200
  358. +++ 7.0/mysys/queues.c 2009-06-04 10:35:49.000000000 +0200
  359. @@ -384,11 +387,11 @@
  360. static uint tot_no_loops= 0;
  361. static uint expected_part= 0;
  362. static uint expected_num= 0;
  363. -static bool max_ind= 0;
  364. -static bool fix_used= 0;
  365. +static my_bool max_ind= 0;
  366. +static my_bool fix_used= 0;
  367. static ulonglong start_time= 0;
  368.  
  369. -static bool is_divisible_by(uint num, uint divisor)
  370. +static my_bool is_divisible_by(uint num, uint divisor)
  371. {
  372. uint quotient= num / divisor;
  373. if (quotient * divisor == num)
  374. @@ -495,7 +498,7 @@
  375. return 0;
  376. }
  377.  
  378. -bool check_num(uint num_part)
  379. +my_bool check_num(uint num_part)
  380. {
  381. uint part= num_part >> 22;
  382. uint num= num_part & 0x3FFFFF;
  383. @@ -546,7 +549,7 @@
  384. }
  385. }
  386.  
  387. -bool perform_ins_del(QUEUE *queue, bool max_ind)
  388. +my_bool perform_ins_del(QUEUE *queue, my_bool max_ind)
  389. {
  390. uint i= 0, no_loops= tot_no_loops, j= tot_no_parts;
  391. do
  392. @@ -574,10 +577,10 @@
  393. return FALSE;
  394. }
  395.  
  396. -bool do_test(uint no_parts, uint l_max_ind, bool l_fix_used)
  397. +my_bool do_test(uint no_parts, uint l_max_ind, my_bool l_fix_used)
  398. {
  399. QUEUE queue;
  400. - bool result;
  401. + my_bool result;
  402. max_ind= l_max_ind;
  403. fix_used= l_fix_used;
  404. init_queue(&queue, no_parts, 0, max_ind, test_compare, NULL);
  405. --- 5.1.34/include/config-win.h 2009-06-03 23:17:27.000000000 +0200
  406. +++ 7.0/include/config-win.h 2009-06-04 10:35:22.000000000 +0200
  407. @@ -33,6 +31,8 @@
  408.  
  409. #include <sys/locking.h>
  410. #include <winsock2.h>
  411. +#include <ws2tcpip.h>
  412. +#include <math.h> /* Because of rint() */
  413. #include <fcntl.h>
  414. #include <io.h>
  415. #include <malloc.h>
  416. @@ -92,6 +92,12 @@
  417.  
  418. #define S_IROTH S_IREAD /* for my_lib */
  419.  
  420. +/* Winsock2 constant (Vista SDK and later)*/
  421. +#define IPPROTO_IPV6 41
  422. +#ifndef IPV6_V6ONLY
  423. +#define IPV6_V6ONLY 27
  424. +#endif
  425. +
  426. #ifdef __BORLANDC__
  427. #define FILE_BINARY O_BINARY /* my_fopen in binary mode */
  428. #define O_TEMPORARY 0
  429. @@ -155,8 +161,14 @@
  430. typedef uint rf_SetTimer;
  431. #endif
  432.  
  433. +#define ssize_t SSIZE_T
  434. +
  435. #define Socket_defined
  436. -#define my_socket SOCKET
  437. +#ifndef __cplusplus
  438. +#define bool BOOL
  439. +#define true ((BOOL)1)
  440. +#define false ((BOOL)0)
  441. +#endif
  442. #define SIGPIPE SIGINT
  443. #define RETQSORTTYPE void
  444. #define QSORT_TYPE_IS_VOID
  445. @@ -280,6 +292,7 @@
  446. #define HAVE_ALLOCA
  447. #define HAVE_STRPBRK
  448. #define HAVE_STRSTR
  449. +#define HAVE_STRDUP
  450. #define HAVE_COMPRESS
  451. #define HAVE_CREATESEMAPHORE
  452. #define HAVE_ISNAN
  453. @@ -307,12 +320,23 @@
  454. #define _snprintf snprintf
  455. #endif
  456.  
  457. +#if _MSC_VER >= 1500 /* VS9 (2008) has vsnprintf */
  458. +#ifndef HAVE_VSNPRINTF
  459. +#define HAVE_VSNPRINTF
  460. +#endif
  461. +#endif
  462. +#ifndef HAVE_STRTOUL
  463. +#define HAVE_STRTOUL
  464. +#endif
  465. +
  466. #ifdef _MSC_VER
  467. #define HAVE_LDIV /* The optimizer breaks in zortech for ldiv */
  468. #define HAVE_ANSI_INCLUDE
  469. #define HAVE_SYS_UTIME_H
  470. +#ifndef HAVE_STRTOUL
  471. #define HAVE_STRTOUL
  472. #endif
  473. +#endif
  474. #define my_reinterpret_cast(A) reinterpret_cast <A>
  475. #define my_const_cast(A) const_cast<A>
  476.  
  477. @@ -417,3 +441,13 @@
  478.  
  479. #define HAVE_UCA_COLLATIONS 1
  480. #define HAVE_BOOL 1
  481. +
  482. +/* Windows doesn't define ENOTSUP, define it as the same as Solaris */
  483. +#ifndef ENOTSUP
  484. +#define ENOTSUP 48
  485. +#endif
  486. +
  487. +#if _MSC_VER >= 1400 /* strtok_s is like strtok_r, but is new */
  488. +#define HAVE_STRTOK_R
  489. +#define strtok_r(A, B, C) strtok_s((A), (B), (C))
  490. +#endif
  491. --- 5.1.34/include/m_string.h 2009-06-03 23:17:27.000000000 +0200
  492. +++ 7.0/include/m_string.h 2009-06-04 10:35:22.000000000 +0200
  493. @@ -215,6 +218,7 @@
  494. long *val);
  495. longlong my_strtoll10(const char *nptr, char **endptr, int *error);
  496. #if SIZEOF_LONG == SIZEOF_LONG_LONG
  497. +#define ll2str(A,B,C,D) int2str((A),(B),(C),(D))
  498. #define longlong2str(A,B,C) int2str((A),(B),(C),1)
  499. #define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C))
  500. #undef strtoll
  501. @@ -228,7 +232,8 @@
  502. #endif
  503. #else
  504. #ifdef HAVE_LONG_LONG
  505. -extern char *longlong2str(longlong val,char *dst,int radix);
  506. +extern char *ll2str(longlong val,char *dst,int radix, int upcase);
  507. +#define longlong2str(A,B,C) ll2str((A),(B),(C),1)
  508. extern char *longlong10_to_str(longlong val,char *dst,int radix);
  509. #if (!defined(HAVE_STRTOULL) || defined(NO_STRTOLL_PROTO))
  510. extern longlong strtoll(const char *str, char **ptr, int base);
  511. --- 5.1.34/include/my_base.h 2009-06-03 23:17:27.000000000 +0200
  512. +++ 7.0/include/my_base.h 2009-06-04 10:35:22.000000000 +0200
  513. @@ -98,6 +101,14 @@
  514. HA_KEY_ALG_FULLTEXT= 4 /* FULLTEXT (MyISAM tables) */
  515. };
  516.  
  517. + /* Index and table build methods */
  518. +
  519. +enum ha_build_method {
  520. + HA_BUILD_DEFAULT,
  521. + HA_BUILD_ONLINE,
  522. + HA_BUILD_OFFLINE
  523. +};
  524. +
  525. /* Storage media types */
  526.  
  527. enum ha_storage_media {
  528. @@ -363,7 +374,11 @@
  529. update handler::auto_increment_value
  530. */
  531. #define HA_STATUS_AUTO 64
  532. -
  533. +/*
  534. + update the number of rows updated and deleted since last reset call.
  535. + handler::rows_updated, rows_deleted
  536. +*/
  537. +#define HA_STATUS_WRITTEN_ROWS 128
  538. /*
  539.   Errorcodes given by handler functions
  540.  
  541. @@ -521,6 +536,8 @@
  542.  #define NULL_RANGE 64
  543.  #define GEOM_FLAG 128
  544.  #define SKIP_RANGE 256
  545. +#define READ_KEY_FROM_RANGE 512
  546. +#define EMPTY_RANGE 1024
  547.  
  548.  typedef struct st_key_range
  549.  {
  550. --- 5.1.34/include/my_global.h 2009-06-03 23:17:47.000000000 +0200
  551. +++ 7.0/include/my_global.h 2009-06-04 10:35:22.000000000 +0200
  552. @@ -156,9 +159,17 @@
  553.  #define __builtin_expect(x, expected_value) (x)
  554.  #endif
  555.  
  556. +#if defined(NDEBUG)
  557.  #define likely(x) __builtin_expect((x),1)
  558.  #define unlikely(x) __builtin_expect((x),0)
  559. -
  560. +#else
  561. +/*
  562. + No branch hinting in DEBUG as this enables warning in case
  563. + of malformed predicates: ie. use of '=' instead of '=='
  564. +*/
  565. +#define likely(x) x
  566. +#define unlikely(x) x
  567. +#endif
  568.  
  569. /*
  570.   The macros below are useful in optimising places where it has been
  571. @@ -678,9 +689,9 @@
  572.  /* Some types that is different between systems */
  573.  
  574. typedef int File; /* File descriptor */
  575. +#include <my_socket.h>
  576. #ifndef Socket_defined
  577. -typedef int my_socket; /* File descriptor for sockets */
  578. -#define INVALID_SOCKET -1
  579. +#define INVALID_SOCKET MY_INVALID_SOCKET
  580. #endif
  581. /* Type for fuctions that handles signals */
  582. #define sig_handler RETSIGTYPE
  583. @@ -816,7 +827,7 @@
  584.  
  585. #undef remove /* Crashes MySQL on SCO 5.0.0 */
  586. #ifndef __WIN__
  587. -#define closesocket(A) close(A)
  588. +#define closesocket(A) my_socket_close(A)
  589. #ifndef ulonglong2double
  590. #define ulonglong2double(A) ((double) (ulonglong) (A))
  591. #define my_off_t2double(A) ((double) (my_off_t) (A))
  592. @@ -1082,22 +1093,24 @@
  593. #endif
  594.  
  595. #if defined(__WIN__)
  596. -#define socket_errno WSAGetLastError()
  597. +#define socket_errno my_socket_errno()
  598. #define SOCKET_EINTR WSAEINTR
  599. #define SOCKET_EAGAIN WSAEINPROGRESS
  600. #define SOCKET_ETIMEDOUT WSAETIMEDOUT
  601. #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
  602. #define SOCKET_EADDRINUSE WSAEADDRINUSE
  603. +#define SOCKET_ECONNREFUSED WSAECONNREFUSED
  604. #define SOCKET_ENFILE ENFILE
  605. #define SOCKET_EMFILE EMFILE
  606. #else /* Unix */
  607. -#define socket_errno errno
  608. -#define closesocket(A) close(A)
  609. +#define socket_errno my_socket_errno()
  610. +#define closesocket(A) my_socket_close(A)
  611. #define SOCKET_EINTR EINTR
  612. #define SOCKET_EAGAIN EAGAIN
  613. #define SOCKET_ETIMEDOUT SOCKET_EINTR
  614. #define SOCKET_EWOULDBLOCK EWOULDBLOCK
  615. #define SOCKET_EADDRINUSE EADDRINUSE
  616. +#define SOCKET_ECONNREFUSED ECONNREFUSED
  617. #define SOCKET_ENFILE ENFILE
  618. #define SOCKET_EMFILE EMFILE
  619. #endif
  620. --- 5.1.34/include/my_pthread.h 2009-06-03 23:17:27.000000000 +0200
  621. +++ 7.0/include/my_pthread.h 2009-06-04 10:35:22.000000000 +0200
  622. @@ -36,6 +39,7 @@
  623. DWORD dwStackSize ;
  624. DWORD dwCreatingFlag ;
  625. int priority ;
  626. + BOOL detached;
  627. } pthread_attr_t ;
  628.  
  629. typedef struct { int dummy; } pthread_condattr_t;
  630. @@ -100,8 +104,6 @@
  631. }
  632.  
  633. void win_pthread_init(void);
  634. -int win_pthread_setspecific(void *A,void *B,uint length);
  635. -int win_pthread_mutex_trylock(pthread_mutex_t *mutex);
  636. int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *);
  637. int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
  638. int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
  639. @@ -113,7 +115,12 @@
  640. int pthread_attr_init(pthread_attr_t *connect_att);
  641. int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack);
  642. int pthread_attr_setprio(pthread_attr_t *connect_att,int priority);
  643. +#define PTHREAD_CREATE_JOINABLE 1
  644. +#define PTHREAD_CREATE_DETACHED 2
  645. +int pthread_attr_setdetachstate(pthread_attr_t *connect_att,int state);
  646. +int pthread_attr_getdetachstate(pthread_attr_t *connect_att,int*state);
  647. int pthread_attr_destroy(pthread_attr_t *connect_att);
  648. +int pthread_join(pthread_t thread, void **value_ptr);
  649. struct tm *localtime_r(const time_t *timep,struct tm *tmp);
  650. struct tm *gmtime_r(const time_t *timep,struct tm *tmp);
  651.  
  652. @@ -126,47 +133,79 @@
  653. #define _REENTRANT 1
  654. #define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1
  655.  
  656. -/*
  657. - Windows has two ways to use thread local storage. The most efficient
  658. - is using __declspec(thread), but that does not work properly when
  659. - used in a .dll that is loaded at runtime, after program load. So for
  660. - libmysql.dll and libmysqld.dll we define USE_TLS in order to use the
  661. - TlsXxx() API instead, which works in all cases.
  662. -*/
  663. -#ifdef USE_TLS /* For LIBMYSQL.DLL */
  664. +
  665. #undef SAFE_MUTEX /* This will cause conflicts */
  666. +typedef DWORD pthread_key_t;
  667. #define pthread_key(T,V) DWORD V
  668. -#define pthread_key_create(A,B) ((*A=TlsAlloc())==0xFFFFFFFF)
  669. -#define pthread_key_delete(A) TlsFree(A)
  670. -#define pthread_getspecific(A) (TlsGetValue(A))
  671. -#define my_pthread_getspecific(T,A) ((T) TlsGetValue(A))
  672. -#define my_pthread_getspecific_ptr(T,V) ((T) TlsGetValue(V))
  673. -#define my_pthread_setspecific_ptr(T,V) (!TlsSetValue((T),(V)))
  674. -#define pthread_setspecific(A,B) (!TlsSetValue((A),(B)))
  675. -#else
  676. -#define pthread_key(T,V) __declspec(thread) T V
  677. -#define pthread_key_create(A,B) pthread_dummy(0)
  678. -#define pthread_key_delete(A) pthread_dummy(0)
  679. -#define pthread_getspecific(A) (&(A))
  680. -#define my_pthread_getspecific(T,A) (&(A))
  681. -#define my_pthread_getspecific_ptr(T,V) (V)
  682. -#define my_pthread_setspecific_ptr(T,V) ((T)=(V),0)
  683. -#define pthread_setspecific(A,B) win_pthread_setspecific(&(A),(B),sizeof(A))
  684. -#endif /* USE_TLS */
  685.  
  686. -#define pthread_equal(A,B) ((A) == (B))
  687. -#define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0)
  688. -#define pthread_mutex_lock(A) (EnterCriticalSection(A),0)
  689. -#define pthread_mutex_trylock(A) win_pthread_mutex_trylock((A))
  690. -#define pthread_mutex_unlock(A) LeaveCriticalSection(A)
  691. -#define pthread_mutex_destroy(A) DeleteCriticalSection(A)
  692. +static inline int pthread_key_create(pthread_key_t *key, void (*destr_function)(void*))
  693. +{
  694. + *key= TlsAlloc();
  695. + if(*key == TLS_OUT_OF_INDEXES)
  696. + return EAGAIN;
  697. + return 0;
  698. +}
  699. +
  700. +static inline int pthread_key_delete(pthread_key_t key)
  701. +{
  702. + if(TlsFree(key))
  703. + return 0;
  704. + return 1;
  705. +}
  706. +
  707. +#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,V)
  708. +
  709. +static inline int pthread_setspecific(pthread_key_t key, const void *pointer)
  710. +{
  711. + if(TlsSetValue(key, (void*)pointer))
  712. + return 0;
  713. + return 1;
  714. +}
  715. +
  716. +static inline void* pthread_getspecific(pthread_key_t key)
  717. +{
  718. + return TlsGetValue(key);
  719. +}
  720. +
  721. +#define my_pthread_getspecific(T,A) ((T) pthread_getspecific(A))
  722. +#define my_pthread_getspecific_ptr(T,V) ((T) pthread_getspecific(V))
  723. +
  724. +static inline int pthread_equal(pthread_t thread1, pthread_t thread2)
  725. +{
  726. + return thread1 == thread2;
  727. +}
  728. +
  729. +typedef void pthread_mutex_attr_t;
  730. +static inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutex_attr_t *mutex_attr)
  731. +{
  732. + InitializeCriticalSection(mutex);
  733. + return 0;
  734. +}
  735. +
  736. +static inline int pthread_mutex_lock(pthread_mutex_t *mutex)
  737. +{
  738. + EnterCriticalSection(mutex);
  739. + return 0;
  740. +}
  741. +
  742. +int pthread_mutex_trylock(pthread_mutex_t *mutex);
  743. +
  744. +static inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
  745. +{
  746. + LeaveCriticalSection(mutex);
  747. + return 0;
  748. +}
  749. +
  750. +static inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
  751. +{
  752. + DeleteCriticalSection(mutex);
  753. + return 0;
  754. +}
  755. +
  756. #define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B))
  757. #define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH)
  758.  
  759. -#define pthread_join(A,B) (WaitForSingleObject((A), INFINITE) != WAIT_OBJECT_0)
  760. -
  761. /* Dummy defines for easier code */
  762. -#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
  763. #define my_pthread_attr_setprio(A,B) pthread_attr_setprio(A,B)
  764. #define pthread_attr_setscope(A,B)
  765. #define pthread_detach_this_thread()
  766. --- 5.1.34/include/mysql.h 2009-06-03 23:17:27.000000000 +0200
  767. +++ 7.0/include/mysql.h 2009-06-04 10:35:22.000000000 +0200
  768. @@ -58,13 +61,6 @@
  769. #define STDCALL __stdcall
  770. #endif
  771.  
  772. -#ifndef my_socket_defined
  773. -#ifdef __WIN__
  774. -#define my_socket SOCKET
  775. -#else
  776. -typedef int my_socket;
  777. -#endif /* __WIN__ */
  778. -#endif /* my_socket_defined */
  779. #endif /* _global_h */
  780.  
  781. #include "mysql_version.h"
  782. @@ -166,7 +162,7 @@
  783. MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
  784. MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
  785. MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
  786. - MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
  787. + MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_BIND,
  788. MYSQL_OPT_SSL_VERIFY_SERVER_CERT
  789. };
  790.  
  791. @@ -206,6 +202,8 @@
  792. #endif
  793. enum mysql_option methods_to_use;
  794. char *client_ip;
  795. + char *bind_name;
  796. +
  797. /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
  798. my_bool secure_auth;
  799. /* 0 - never report, 1 - always report (default) */
  800. --- 5.1.34/include/mysql.h.pp 2009-06-03 23:17:27.000000000 +0200
  801. +++ 7.0/include/mysql.h.pp 2009-06-04 10:35:22.000000000 +0200
  802. @@ -1,6 +1,5 @@
  803. #include <sys/types.h>
  804. typedef char my_bool;
  805. -typedef int my_socket;
  806. #include "mysql_version.h"
  807. #include "mysql_com.h"
  808. enum enum_server_command
  809. @@ -19,7 +18,7 @@
  810. typedef struct st_net {
  811. Vio *vio;
  812. unsigned char *buff,*buff_end,*write_pos,*read_pos;
  813. - my_socket fd;
  814. + int fd;
  815. unsigned long remain_in_buf,length, buf_length, where_b;
  816. unsigned long max_packet,max_packet_size;
  817. unsigned int pkt_nr,compress_pkt_nr;
  818. @@ -42,24 +41,25 @@
  819. void *extension;
  820. } NET;
  821. enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
  822. - MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
  823. - MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
  824. - MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
  825. - MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  826. - MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
  827. - MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  828. - MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
  829. - MYSQL_TYPE_BIT,
  830. + MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
  831. + MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
  832. + MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
  833. + MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  834. + MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
  835. + MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  836. + MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
  837. + MYSQL_TYPE_BIT,
  838. MYSQL_TYPE_NEWDECIMAL=246,
  839. - MYSQL_TYPE_ENUM=247,
  840. - MYSQL_TYPE_SET=248,
  841. - MYSQL_TYPE_TINY_BLOB=249,
  842. - MYSQL_TYPE_MEDIUM_BLOB=250,
  843. - MYSQL_TYPE_LONG_BLOB=251,
  844. - MYSQL_TYPE_BLOB=252,
  845. - MYSQL_TYPE_VAR_STRING=253,
  846. - MYSQL_TYPE_STRING=254,
  847. - MYSQL_TYPE_GEOMETRY=255
  848. + MYSQL_TYPE_ENUM=247,
  849. + MYSQL_TYPE_SET=248,
  850. + MYSQL_TYPE_TINY_BLOB=249,
  851. + MYSQL_TYPE_MEDIUM_BLOB=250,
  852. + MYSQL_TYPE_LONG_BLOB=251,
  853. + MYSQL_TYPE_BLOB=252,
  854. + MYSQL_TYPE_VAR_STRING=253,
  855. + MYSQL_TYPE_STRING=254,
  856. + MYSQL_TYPE_GEOMETRY=255,
  857. + MAX_NO_FIELD_TYPES
  858. };
  859. enum mysql_enum_shutdown_level {
  860. SHUTDOWN_DEFAULT = 0,
  861. @@ -96,14 +96,16 @@
  862. int net_real_write(NET *net,const unsigned char *packet, size_t len);
  863. unsigned long my_net_read(NET *net);
  864. struct sockaddr;
  865. -int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
  866. +int my_connect(int s, const struct sockaddr *name, unsigned int namelen,
  867. unsigned int timeout);
  868. struct rand_struct {
  869. unsigned long seed1,seed2,max_value;
  870. double max_value_dbl;
  871. };
  872. enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
  873. - DECIMAL_RESULT};
  874. + DECIMAL_RESULT,
  875. + MAX_NO_ITEM_RESULTS
  876. +};
  877. typedef struct st_udf_args
  878. {
  879. unsigned int arg_count;
  880. @@ -258,7 +260,7 @@
  881. MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
  882. MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
  883. MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
  884. - MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
  885. + MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_BIND,
  886. MYSQL_OPT_SSL_VERIFY_SERVER_CERT
  887. };
  888. struct st_mysql_options {
  889. @@ -283,6 +285,7 @@
  890. my_bool separate_thread;
  891. enum mysql_option methods_to_use;
  892. char *client_ip;
  893. + char *bind_name;
  894. my_bool secure_auth;
  895. my_bool report_data_truncation;
  896. int (*local_infile_init)(void **, const char *, void *);
  897. --- 5.1.34/include/mysql_com.h 2009-06-03 23:17:27.000000000 +0200
  898. +++ 7.0/include/mysql_com.h 2009-06-04 10:35:22.000000000 +0200
  899. @@ -104,6 +107,8 @@
  900. #define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */
  901. #define FIELD_IN_ADD_INDEX (1<< 20) /* Intern: Field used in ADD INDEX */
  902. #define FIELD_IS_RENAMED (1<< 21) /* Intern: Field is being renamed */
  903. +#define FIELD_STORAGE_FLAGS 22 /* Storage type: bit 22, 23 and 24 */
  904. +#define COLUMN_FORMAT_FLAGS 25 /* Column format: bit 25, 26 and 27 */
  905.  
  906. #define REFRESH_GRANT 1 /* Refresh grant tables */
  907. #define REFRESH_LOG 2 /* Start on new log file */
  908. @@ -240,7 +245,11 @@
  909. #if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)
  910. Vio *vio;
  911. unsigned char *buff,*buff_end,*write_pos,*read_pos;
  912. - my_socket fd; /* For Perl DBI/dbd */
  913. +#ifdef __WIN__
  914. + SOCKET fd;
  915. +#else
  916. + int fd; /* For Perl DBI/dbd */
  917. +#endif
  918. /*
  919.   The following variable is set if we are doing several queries in one
  920.   command ( as in LOAD TABLE ... FROM MASTER ),
  921. @@ -283,25 +292,25 @@
  922.  #define packet_error (~(unsigned long) 0)
  923.  
  924.  enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
  925. - MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
  926. - MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
  927. - MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
  928. - MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  929. - MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
  930. - MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  931. - MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
  932. - MYSQL_TYPE_BIT,
  933. + MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
  934. + MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
  935. + MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
  936. + MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  937. + MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
  938. + MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  939. + MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
  940. + MYSQL_TYPE_BIT,
  941.   MYSQL_TYPE_NEWDECIMAL=246,
  942. - MYSQL_TYPE_ENUM=247,
  943. - MYSQL_TYPE_SET=248,
  944. - MYSQL_TYPE_TINY_BLOB=249,
  945. - MYSQL_TYPE_MEDIUM_BLOB=250,
  946. - MYSQL_TYPE_LONG_BLOB=251,
  947. - MYSQL_TYPE_BLOB=252,
  948. - MYSQL_TYPE_VAR_STRING=253,
  949. - MYSQL_TYPE_STRING=254,
  950. - MYSQL_TYPE_GEOMETRY=255
  951. -
  952. + MYSQL_TYPE_ENUM=247,
  953. + MYSQL_TYPE_SET=248,
  954. + MYSQL_TYPE_TINY_BLOB=249,
  955. + MYSQL_TYPE_MEDIUM_BLOB=250,
  956. + MYSQL_TYPE_LONG_BLOB=251,
  957. + MYSQL_TYPE_BLOB=252,
  958. + MYSQL_TYPE_VAR_STRING=253,
  959. + MYSQL_TYPE_STRING=254,
  960. + MYSQL_TYPE_GEOMETRY=255,
  961. + MAX_NO_FIELD_TYPES /* Should always be last */
  962. };
  963.  
  964. /* For backward compatibility */
  965. @@ -414,8 +423,13 @@
  966. Currently it's used internally by manager.c
  967. */
  968. struct sockaddr;
  969. -int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
  970. +#ifdef __WIN__
  971. +int my_connect(SOCKET s, const struct sockaddr *name, unsigned int namelen,
  972. unsigned int timeout);
  973. +#else
  974. +int my_connect(int s, const struct sockaddr *name, unsigned int namelen,
  975. + unsigned int timeout);
  976. +#endif
  977.  
  978. struct rand_struct {
  979. unsigned long seed1,seed2,max_value;
  980. @@ -429,7 +443,9 @@
  981. /* The following is for user defined functions */
  982.  
  983. enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
  984. - DECIMAL_RESULT};
  985. + DECIMAL_RESULT,
  986. + MAX_NO_ITEM_RESULTS /* Should always be last */
  987. +};
  988.  
  989. typedef struct st_udf_args
  990. {
  991. --- 5.1.34/include/violite.h 2009-06-03 23:17:27.000000000 +0200
  992. +++ 7.0/include/violite.h 2009-06-04 10:35:22.000000000 +0200
  993. @@ -84,9 +87,7 @@
  994. /* Get socket number */
  995. my_socket vio_fd(Vio*vio);
  996. /* Remote peer's address and name in text form */
  997. -my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port);
  998. -/* Remotes in_addr */
  999. -void vio_in_addr(Vio *vio, struct in_addr *in);
  1000. +my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port, size_t buflen);
  1001. my_bool vio_poll_read(Vio *vio,uint timeout);
  1002.  
  1003. #ifdef HAVE_OPENSSL
  1004. @@ -103,9 +104,6 @@
  1005. #ifndef YASSL_PREFIX
  1006. #define YASSL_PREFIX
  1007. #endif
  1008. -/* Set yaSSL to use same type as MySQL do for socket handles */
  1009. -typedef my_socket YASSL_SOCKET_T;
  1010. -#define YASSL_SOCKET_T_DEFINED
  1011. #include <openssl/ssl.h>
  1012. #include <openssl/err.h>
  1013.  
  1014. @@ -153,8 +151,7 @@
  1015. #define vio_should_retry(vio) (vio)->should_retry(vio)
  1016. #define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
  1017. #define vio_close(vio) ((vio)->vioclose)(vio)
  1018. -#define vio_peer_addr(vio, buf, prt) (vio)->peer_addr(vio, buf, prt)
  1019. -#define vio_in_addr(vio, in) (vio)->in_addr(vio, in)
  1020. +#define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
  1021. #define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
  1022. #endif /* !defined(DONT_MAP_VIO) */
  1023.  
  1024. @@ -177,8 +174,9 @@
  1025. HANDLE hPipe;
  1026. my_bool localhost; /* Are we from localhost? */
  1027. int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
  1028. - struct sockaddr_in local; /* Local internet address */
  1029. - struct sockaddr_in remote; /* Remote internet address */
  1030. + struct sockaddr_storage local; /* Local internet address */
  1031. + struct sockaddr_storage remote; /* Remote internet address */
  1032. + int addrLen; /* Length of remote address */
  1033. enum enum_vio_type type; /* Type of connection */
  1034. char desc[30]; /* String description */
  1035. char *read_buffer; /* buffer for vio_read_buff */
  1036. @@ -194,8 +192,8 @@
  1037. my_bool (*is_blocking)(Vio*);
  1038. int (*viokeepalive)(Vio*, my_bool);
  1039. int (*fastsend)(Vio*);
  1040. - my_bool (*peer_addr)(Vio*, char *, uint16*);
  1041. - void (*in_addr)(Vio*, struct in_addr*);
  1042. + my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
  1043. + void (*in_addr)(Vio*, struct sockaddr_storage*);
  1044. my_bool (*should_retry)(Vio*);
  1045. my_bool (*was_interrupted)(Vio*);
  1046. int (*vioclose)(Vio*);
  1047. --- 5.1.34/client/CMakeLists.txt 2009-06-03 23:17:27.000000000 +0200
  1048. +++ 7.0/client/CMakeLists.txt 2009-06-04 10:35:19.000000000 +0200
  1049. @@ -30,27 +27,27 @@
  1050. ${CMAKE_SOURCE_DIR}/strings)
  1051.  
  1052. ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc sql_string.cc ../mysys/my_conio.c)
  1053. -TARGET_LINK_LIBRARIES(mysql mysqlclient_notls wsock32)
  1054. +TARGET_LINK_LIBRARIES(mysql mysqlclient wsock32)
  1055.  
  1056. ADD_EXECUTABLE(mysqltest mysqltest.cc)
  1057. SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS")
  1058. TARGET_LINK_LIBRARIES(mysqltest mysqlclient mysys regex wsock32 dbug)
  1059.  
  1060. ADD_EXECUTABLE(mysqlcheck mysqlcheck.c)
  1061. -TARGET_LINK_LIBRARIES(mysqlcheck mysqlclient_notls wsock32)
  1062. +TARGET_LINK_LIBRARIES(mysqlcheck mysqlclient wsock32)
  1063.  
  1064. ADD_EXECUTABLE(mysqldump mysqldump.c ../sql-common/my_user.c ../mysys/mf_getdate.c)
  1065. -TARGET_LINK_LIBRARIES(mysqldump mysqlclient_notls wsock32)
  1066. +TARGET_LINK_LIBRARIES(mysqldump mysqlclient wsock32)
  1067.  
  1068. ADD_EXECUTABLE(mysqlimport mysqlimport.c)
  1069. -TARGET_LINK_LIBRARIES(mysqlimport mysqlclient_notls wsock32)
  1070. +TARGET_LINK_LIBRARIES(mysqlimport mysqlclient wsock32)
  1071.  
  1072. ADD_EXECUTABLE(mysql_upgrade mysql_upgrade.c ../mysys/my_getpagesize.c)
  1073. -TARGET_LINK_LIBRARIES(mysql_upgrade mysqlclient_notls wsock32)
  1074. +TARGET_LINK_LIBRARIES(mysql_upgrade mysqlclient wsock32)
  1075. ADD_DEPENDENCIES(mysql_upgrade GenFixPrivs)
  1076.  
  1077. ADD_EXECUTABLE(mysqlshow mysqlshow.c)
  1078. -TARGET_LINK_LIBRARIES(mysqlshow mysqlclient_notls wsock32)
  1079. +TARGET_LINK_LIBRARIES(mysqlshow mysqlclient wsock32)
  1080.  
  1081. ADD_EXECUTABLE(mysqlbinlog mysqlbinlog.cc
  1082. ../mysys/mf_tempdir.c
  1083. @@ -59,10 +56,10 @@
  1084. ../mysys/my_bitmap.c
  1085. ../mysys/my_vle.c
  1086. ../mysys/base64.c)
  1087. -TARGET_LINK_LIBRARIES(mysqlbinlog mysqlclient_notls wsock32)
  1088. +TARGET_LINK_LIBRARIES(mysqlbinlog mysqlclient wsock32)
  1089.  
  1090. ADD_EXECUTABLE(mysqladmin mysqladmin.cc)
  1091. -TARGET_LINK_LIBRARIES(mysqladmin mysqlclient_notls wsock32)
  1092. +TARGET_LINK_LIBRARIES(mysqladmin mysqlclient wsock32)
  1093.  
  1094. ADD_EXECUTABLE(mysqlslap mysqlslap.c)
  1095. SET_SOURCE_FILES_PROPERTIES(mysqlslap.c PROPERTIES COMPILE_FLAGS "-DTHREADS")
  1096. --- 5.1.34/client/mysql.cc 2009-06-03 23:17:47.000000000 +0200
  1097. +++ 7.0/client/mysql.cc 2009-06-04 10:35:19.000000000 +0200
  1098. @@ -151,6 +154,7 @@
  1099. static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
  1100. static uint my_end_arg;
  1101. static char * opt_mysql_unix_port=0;
  1102. +static char *opt_bind_addr = NULL;
  1103. static int connect_flag=CLIENT_INTERACTIVE;
  1104. static char *current_host,*current_db,*current_user=0,*opt_password=0,
  1105. *current_prompt=0, *delimiter_str= 0,
  1106. @@ -1324,6 +1328,9 @@
  1107. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  1108. {"batch", 'B',
  1109. "Don't use history file. Disable interactive behavior. (Enables --silent)", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  1110. + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
  1111. + (uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
  1112. + REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1113. {"character-sets-dir", OPT_CHARSETS_DIR,
  1114. "Directory where character sets are.", (uchar**) &charsets_dir,
  1115. (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1116. @@ -4148,6 +4155,10 @@
  1117. mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT,
  1118. (char*) &timeout);
  1119. }
  1120. + if (opt_bind_addr)
  1121. + {
  1122. + mysql_options(&mysql, MYSQL_OPT_BIND, opt_bind_addr);
  1123. + }
  1124. if (opt_compress)
  1125. mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
  1126. if (opt_secure_auth)
  1127. --- 5.1.34/client/mysqladmin.cc 2009-06-03 23:17:47.000000000 +0200
  1128. +++ 7.0/client/mysqladmin.cc 2009-06-04 10:35:19.000000000 +0200
  1129. @@ -40,6 +43,7 @@
  1130. static my_bool debug_info_flag= 0, debug_check_flag= 0;
  1131. static uint tcp_port = 0, option_wait = 0, option_silent=0, nr_iterations;
  1132. static uint opt_count_iterations= 0, my_end_arg;
  1133. +static char *opt_bind_addr = NULL;
  1134. static ulong opt_connect_timeout, opt_shutdown_timeout;
  1135. static char * unix_port=0;
  1136.  
  1137. @@ -119,6 +123,9 @@
  1138. {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
  1139. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  1140. #endif
  1141. + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
  1142. + (uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
  1143. + REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1144. {"count", 'c',
  1145. "Number of iterations to make. This works with -i (--sleep) only.",
  1146. (uchar**) &nr_iterations, (uchar**) &nr_iterations, 0, GET_UINT,
  1147. @@ -325,6 +332,10 @@
  1148. VOID(signal(SIGINT,endprog)); /* Here if abort */
  1149. VOID(signal(SIGTERM,endprog)); /* Here if abort */
  1150.  
  1151. + if (opt_bind_addr)
  1152. + {
  1153. + mysql_options(&mysql,MYSQL_OPT_BIND,opt_bind_addr);
  1154. + }
  1155. if (opt_compress)
  1156. mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
  1157. if (opt_connect_timeout)
  1158. --- 5.1.34/client/mysqlbinlog.cc 2009-06-03 23:17:47.000000000 +0200
  1159. +++ 7.0/client/mysqlbinlog.cc 2009-06-04 10:35:19.000000000 +0200
  1160. @@ -82,6 +85,7 @@
  1161. static const char* sock= 0;
  1162. static const char* user = 0;
  1163. static char* pass = 0;
  1164. +static char *opt_bind_addr = NULL;
  1165. static char *charset= 0;
  1166.  
  1167. static uint verbose= 0;
  1168. @@ -944,6 +948,9 @@
  1169. ,(uchar**) &opt_base64_output_mode_str,
  1170. (uchar**) &opt_base64_output_mode_str,
  1171. 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
  1172. + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
  1173. + (uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
  1174. + REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1175. /*
  1176.   mysqlbinlog needs charsets knowledge, to be able to convert a charset
  1177.   number found in binlog to a charset name (to be able to print things
  1178. @@ -1319,6 +1326,10 @@
  1179.  
  1180.   if (opt_protocol)
  1181.   mysql_options(mysql, MYSQL_OPT_PROTOCOL, (char*) &opt_protocol);
  1182. + if (opt_bind_addr)
  1183. + {
  1184. + mysql_options(mysql, MYSQL_OPT_BIND, opt_bind_addr);
  1185. + }
  1186.   if (!mysql_real_connect(mysql, host, user, pass, 0, port, sock, 0))
  1187.   {
  1188.   error("Failed on connect: %s", mysql_error(mysql));
  1189. --- 5.1.34/client/mysqlcheck.c 2009-06-03 23:17:47.000000000 +0200
  1190. +++ 7.0/client/mysqlcheck.c 2009-06-04 10:35:19.000000000 +0200
  1191. @@ -47,6 +50,7 @@
  1192.  static char *shared_memory_base_name=0;
  1193.  #endif
  1194.  static uint opt_protocol=0;
  1195. +static char *opt_bind_addr = NULL;
  1196.  
  1197.  enum operations { DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
  1198.  
  1199. @@ -70,6 +74,9 @@
  1200.   "If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",
  1201.   (uchar**) &opt_auto_repair, (uchar**) &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,
  1202.   0, 0, 0, 0, 0},
  1203. + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
  1204. + (uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
  1205. + REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1206.   {"character-sets-dir", OPT_CHARSETS_DIR,
  1207.   "Directory where character sets are.", (uchar**) &charsets_dir,
  1208.   (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1209. @@ -781,6 +788,10 @@
  1210.  #endif
  1211.   if (opt_protocol)
  1212.   mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
  1213. + if (opt_bind_addr)
  1214. + {
  1215. + mysql_options(&mysql_connection,MYSQL_OPT_BIND,opt_bind_addr);
  1216. + }
  1217.  #ifdef HAVE_SMEM
  1218.   if (shared_memory_base_name)
  1219.   mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
  1220. --- 5.1.34/client/mysqldump.c 2009-06-03 23:17:47.000000000 +0200
  1221. +++ 7.0/client/mysqldump.c 2009-06-04 10:35:19.000000000 +0200
  1222. @@ -119,6 +122,7 @@
  1223.  #define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
  1224.  #define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
  1225.  static uint opt_mysql_port= 0, opt_master_data;
  1226. +static char *opt_bind_addr = NULL;
  1227.  static uint my_end_arg;
  1228.  static char * opt_mysql_unix_port=0;
  1229.  static int first_error=0;
  1230. @@ -210,6 +214,9 @@
  1231.   {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
  1232.   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  1233.  #endif
  1234. + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
  1235. + (uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
  1236. + REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1237.   {"character-sets-dir", OPT_CHARSETS_DIR,
  1238.   "Directory where character sets are.", (uchar**) &charsets_dir,
  1239.   (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1240. @@ -1463,6 +1470,10 @@
  1241.  #endif
  1242.   if (opt_protocol)
  1243.   mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
  1244. + if (opt_bind_addr)
  1245. + {
  1246. + mysql_options(&mysql_connection,MYSQL_OPT_BIND,opt_bind_addr);
  1247. + }
  1248.  #ifdef HAVE_SMEM
  1249.   if (shared_memory_base_name)
  1250.   mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
  1251. --- 5.1.34/client/mysqlimport.c 2009-06-03 23:17:47.000000000 +0200
  1252. +++ 7.0/client/mysqlimport.c 2009-06-04 10:35:19.000000000 +0200
  1253. @@ -57,6 +60,7 @@
  1254.   *escaped=0, *opt_columns=0,
  1255.   *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
  1256.  static uint opt_mysql_port= 0, opt_protocol= 0;
  1257. +static char *opt_bind_addr = NULL;
  1258.  static char * opt_mysql_unix_port=0;
  1259.  static longlong opt_ignore_lines= -1;
  1260.  static CHARSET_INFO *charset_info= &my_charset_latin1;
  1261. @@ -72,6 +76,9 @@
  1262.   {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
  1263.   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  1264.  #endif
  1265. + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
  1266. + (uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
  1267. + REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1268.   {"character-sets-dir", OPT_CHARSETS_DIR,
  1269.   "Directory where character sets are.", (uchar**) &charsets_dir,
  1270.   (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1271. @@ -423,6 +430,8 @@
  1272.  #endif
  1273.   if (opt_protocol)
  1274.   mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
  1275. + if (opt_bind_addr)
  1276. + mysql_options(mysql,MYSQL_OPT_BIND,opt_bind_addr);
  1277.  #ifdef HAVE_SMEM
  1278.   if (shared_memory_base_name)
  1279.   mysql_options(mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
  1280. --- 5.1.34/client/mysqlshow.c 2009-06-03 23:17:47.000000000 +0200
  1281. +++ 7.0/client/mysqlshow.c 2009-06-04 10:35:19.000000000 +0200
  1282. @@ -38,6 +41,7 @@
  1283.  static char *shared_memory_base_name=0;
  1284.  #endif
  1285.  static uint opt_protocol=0;
  1286. +static char *opt_bind_addr = NULL;
  1287.  
  1288.  static void get_options(int *argc,char ***argv);
  1289.  static uint opt_mysql_port=0;
  1290. @@ -115,6 +119,10 @@
  1291.  #endif
  1292.   if (opt_protocol)
  1293.   mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
  1294. + if (opt_bind_addr)
  1295. + {
  1296. + mysql_options(&mysql,MYSQL_OPT_BIND,opt_bind_addr);
  1297. + }
  1298.  #ifdef HAVE_SMEM
  1299.   if (shared_memory_base_name)
  1300.   mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
  1301. @@ -163,6 +171,9 @@
  1302.   {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
  1303.   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  1304.  #endif
  1305. + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
  1306. + (uchar**) &opt_bind_addr, (uchar**) &opt_bind_addr, 0, GET_STR,
  1307. + REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1308.   {"character-sets-dir", 'c', "Directory where character sets are.",
  1309.   (uchar**) &charsets_dir, (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0,
  1310.   0, 0, 0, 0, 0},
  1311. --- 5.1.34/client/mysqltest.cc 2009-06-03 23:17:46.000000000 +0200
  1312. +++ 7.0/client/mysqltest.cc 2009-06-04 10:35:19.000000000 +0200
  1313. @@ -75,7 +78,8 @@
  1314.  enum {
  1315.   OPT_SKIP_SAFEMALLOC=OPT_MAX_CLIENT_OPTION,
  1316.   OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
  1317. - OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
  1318. + OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES,
  1319. + OPT_RESULT_FORMAT_VERSION
  1320.  };
  1321.  
  1322.  static int record= 0, opt_sleep= -1;
  1323. @@ -85,6 +89,7 @@
  1324.  const char *opt_include= 0, *opt_charsets_dir;
  1325.  static int opt_port= 0;
  1326.  static int opt_max_connect_retries;
  1327. +static int opt_result_format_version;
  1328.  static my_bool opt_compress= 0, silent= 0, verbose= 0;
  1329.  static my_bool debug_info_flag= 0, debug_check_flag= 0;
  1330.  static my_bool tty_password= 0;
  1331. @@ -280,10 +285,12 @@
  1332.   Q_SEND_QUIT, Q_CHANGE_USER, Q_MKDIR, Q_RMDIR,
  1333.   Q_LIST_FILES, Q_LIST_FILES_WRITE_FILE, Q_LIST_FILES_APPEND_FILE,
  1334.   Q_SEND_SHUTDOWN, Q_SHUTDOWN_SERVER,
  1335. + Q_RESULT_FORMAT_VERSION,
  1336.  
  1337.   Q_UNKNOWN, /* Unknown command. */
  1338. Q_COMMENT, /* Comments, ignored. */
  1339. - Q_COMMENT_WITH_COMMAND
  1340. + Q_COMMENT_WITH_COMMAND,
  1341. + Q_EMPTY_LINE
  1342. };
  1343.  
  1344.  
  1345. @@ -376,6 +383,7 @@
  1346. "list_files_append_file",
  1347. "send_shutdown",
  1348. "shutdown_server",
  1349. + "result_format",
  1350.  
  1351. 0
  1352. };
  1353. @@ -2175,6 +2183,59 @@
  1354. }
  1355.  
  1356.  
  1357. +static void
  1358. +set_result_format_version(ulong new_version)
  1359. +{
  1360. + switch (new_version){
  1361. + case 1:
  1362. + /* The first format */
  1363. + break;
  1364. + case 2:
  1365. + /* New format that also writes comments and empty lines
  1366. + from test file to result */
  1367. + break;
  1368. + default:
  1369. + die("Version format %lu has not yet been implemented", new_version);
  1370. + break;
  1371. + }
  1372. + opt_result_format_version= new_version;
  1373. +}
  1374. +
  1375. +
  1376. +/*
  1377. + Set the result format version to use when generating
  1378. + the .result file
  1379. +*/
  1380. +
  1381. +static void
  1382. +do_result_format_version(struct st_command *command)
  1383. +{
  1384. + long version;
  1385. + static DYNAMIC_STRING ds_version;
  1386. + const struct command_arg result_format_args[] = {
  1387. + "version", ARG_STRING, TRUE, &ds_version, "Version to use",
  1388. + };
  1389. +
  1390. + DBUG_ENTER("do_result_format_version");
  1391. +
  1392. + check_command_args(command, command->first_argument,
  1393. + result_format_args,
  1394. + sizeof(result_format_args)/sizeof(struct command_arg),
  1395. + ',');
  1396. +
  1397. + /* Convert version number to int */
  1398. + if (!str2int(ds_version.str, 10, (long) 0, (long) INT_MAX, &version))
  1399. + die("Invalid version number: '%s'", ds_version.str);
  1400. +
  1401. + set_result_format_version(version);
  1402. +
  1403. + dynstr_append(&ds_res, "result_format: ");
  1404. + dynstr_append_mem(&ds_res, ds_version.str, ds_version.length);
  1405. + dynstr_append(&ds_res, "\n");
  1406. + dynstr_free(&ds_version);
  1407. +}
  1408. +
  1409. +
  1410. /*
  1411.   Set variable from the result of a field in a query
  1412.  
  1413. @@ -2568,6 +2629,9 @@
  1414.  }
  1415.  
  1416.  
  1417. +/* where to put this declaration in the file? */
  1418. +int regex_replace(DYNAMIC_STRING *ds, char *expr);
  1419. +
  1420. /*
  1421.   Execute given command.
  1422.  
  1423. @@ -2619,12 +2683,18 @@
  1424.  
  1425.  #ifdef __WIN__
  1426.  #ifndef USE_CYGWIN
  1427. - /* Replace /dev/null with NUL */
  1428. - while(replace(&ds_cmd, "/dev/null", 9, "NUL", 3) == 0)
  1429. - ;
  1430. - /* Replace "closed stdout" with non existing output fd */
  1431. - while(replace(&ds_cmd, ">&-", 3, ">&4", 3) == 0)
  1432. - ;
  1433. + {
  1434. + char *replaces[]= {
  1435. + /* Replace /dev/null with NUL */
  1436. + "/\\/dev\\/null/NUL/",
  1437. + /* Replace "closed stdout" with non existing output fd */
  1438. + "/>&-/>&4/",
  1439. + 0
  1440. + };
  1441. + int i= 0;
  1442. + for(;replaces[i];i++)
  1443. + regex_replace(&ds_cmd, replaces[i]);
  1444. + }
  1445. #endif
  1446. #endif
  1447.  
  1448. @@ -5185,7 +5255,7 @@
  1449.  
  1450. int read_line(char *buf, int size)
  1451. {
  1452. - char c, last_quote;
  1453. + char c, last_quote, last_char= 0;
  1454. char *p= buf, *buf_end= buf + size - 1;
  1455. int skip_char= 0;
  1456. enum {R_NORMAL, R_Q, R_SLASH_IN_Q,
  1457. @@ -5284,14 +5354,24 @@
  1458. }
  1459. else if (my_isspace(charset_info, c))
  1460. {
  1461. - /* Skip all space at begining of line */
  1462. if (c == '\n')
  1463. {
  1464. + if (last_char == '\n')
  1465. + {
  1466. + /* Two new lines in a row, return empty line */
  1467. + DBUG_PRINT("info", ("Found two new lines in a row"));
  1468. + *p++= c;
  1469. + *p= 0;
  1470. + DBUG_RETURN(0);
  1471. + }
  1472. +
  1473. /* Query hasn't started yet */
  1474. start_lineno= cur_file->lineno;
  1475. DBUG_PRINT("info", ("Query hasn't started yet, start_lineno: %d",
  1476. start_lineno));
  1477. }
  1478. +
  1479. + /* Skip all space at begining of line */
  1480. skip_char= 1;
  1481. }
  1482. else if (end_of_query(c))
  1483. @@ -5332,6 +5412,8 @@
  1484.  
  1485. }
  1486.  
  1487. + last_char= c;
  1488. +
  1489. if (!skip_char)
  1490. {
  1491. /* Could be a multibyte character */
  1492. @@ -5541,9 +5623,10 @@
  1493. DBUG_RETURN(1);
  1494. }
  1495.  
  1496. - convert_to_format_v1(read_command_buf);
  1497. + if (opt_result_format_version == 1)
  1498. + convert_to_format_v1(read_command_buf);
  1499.  
  1500. - DBUG_PRINT("info", ("query: %s", read_command_buf));
  1501. + DBUG_PRINT("info", ("query: '%s'", read_command_buf));
  1502. if (*p == '#')
  1503. {
  1504. command->type= Q_COMMENT;
  1505. @@ -5553,6 +5636,10 @@
  1506. command->type= Q_COMMENT_WITH_COMMAND;
  1507. p+= 2; /* Skip past -- */
  1508. }
  1509. + else if (*p == '\n')
  1510. + {
  1511. + command->type= Q_EMPTY_LINE;
  1512. + }
  1513.  
  1514. /* Skip leading spaces */
  1515. while (*p && my_isspace(charset_info, *p))
  1516. @@ -5647,6 +5734,11 @@
  1517. {"result-file", 'R', "Read/Store result from/in this file.",
  1518. (uchar**) &result_file_name, (uchar**) &result_file_name, 0,
  1519. GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1520. + {"result-format-version", OPT_RESULT_FORMAT_VERSION,
  1521. + "Version of the result file format to use",
  1522. + (uchar**) &opt_result_format_version,
  1523. + (uchar**) &opt_result_format_version, 0,
  1524. + GET_INT, REQUIRED_ARG, 1, 1, 2, 0, 0, 0},
  1525. {"server-arg", 'A', "Send option value to embedded server as a parameter.",
  1526. 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  1527. {"server-file", 'F', "Read embedded server arguments from file.",
  1528. @@ -5843,6 +5935,9 @@
  1529. sf_malloc_quick=1;
  1530. #endif
  1531. break;
  1532. + case OPT_RESULT_FORMAT_VERSION:
  1533. + set_result_format_version(opt_result_format_version);
  1534. + break;
  1535. case 'V':
  1536. print_version();
  1537. exit(0);
  1538. @@ -7680,6 +7775,7 @@
  1539. case Q_COPY_FILE: do_copy_file(command); break;
  1540. case Q_CHMOD_FILE: do_chmod_file(command); break;
  1541. case Q_PERL: do_perl(command); break;
  1542. + case Q_RESULT_FORMAT_VERSION: do_result_format_version(command); break;
  1543. case Q_DELIMITER:
  1544. do_delimiter(command);
  1545. break;
  1546. @@ -7796,9 +7892,38 @@
  1547. do_sync_with_master2(command, 0);
  1548. break;
  1549. }
  1550. - case Q_COMMENT: /* Ignore row */
  1551. + case Q_COMMENT:
  1552. + {
  1553. + const char* p= command->query;
  1554. command->last_argument= command->end;
  1555. +
  1556. + /* Don't output comments in v1 */
  1557. + if (opt_result_format_version == 1)
  1558. + break;
  1559. +
  1560. + /* Don't output comments if query logging is off */
  1561. + if (disable_query_log)
  1562. + break;
  1563. +
  1564. + /* Write comment's with two starting #'s to result file */
  1565. + if (p && *p == '#' && *(p+1) == '#')
  1566. + {
  1567. + dynstr_append_mem(&ds_res, command->query, command->query_len);
  1568. + dynstr_append(&ds_res, "\n");
  1569. + }
  1570. break;
  1571. + }
  1572. + case Q_EMPTY_LINE:
  1573. + /* Don't output newline in v1 */
  1574. + if (opt_result_format_version == 1)
  1575. + break;
  1576. +
  1577. + /* Don't output newline if query logging is off */
  1578. + if (disable_query_log)
  1579. + break;
  1580. +
  1581. + dynstr_append(&ds_res, "\n");
  1582. + break;
  1583. case Q_PING:
  1584. handle_command_error(command, mysql_ping(&cur_con->mysql));
  1585. break;
  1586. @@ -8475,15 +8600,31 @@
  1587. command->last_argument= command->end;
  1588. }
  1589.  
  1590. +/* where to put these functions in the file? */
  1591. +void free_regex(struct st_replace_regex* r)
  1592. +{
  1593. + delete_dynamic(&r->regex_arr);
  1594. + my_free(r->even_buf,MYF(MY_ALLOW_ZERO_PTR));
  1595. + my_free(r->odd_buf,MYF(MY_ALLOW_ZERO_PTR));
  1596. + my_free(r,MYF(0));
  1597. +}
  1598. +
  1599. +/* where to put these functions in the file? */
  1600. +int regex_replace(DYNAMIC_STRING *ds, char *expr)
  1601. +{
  1602. + struct st_replace_regex* r= init_replace_regex(expr);
  1603. + int rv= multi_reg_replace(r, ds->str);
  1604. + dynstr_set(ds, r->buf);
  1605. + free_regex(r);
  1606. + return rv;
  1607. +}
  1608. +
  1609. void free_replace_regex()
  1610. {
  1611. if (glob_replace_regex)
  1612. {
  1613. - delete_dynamic(&glob_replace_regex->regex_arr);
  1614. - my_free(glob_replace_regex->even_buf,MYF(MY_ALLOW_ZERO_PTR));
  1615. - my_free(glob_replace_regex->odd_buf,MYF(MY_ALLOW_ZERO_PTR));
  1616. - my_free(glob_replace_regex,MYF(0));
  1617. - glob_replace_regex=0;
  1618. + free_regex(glob_replace_regex);
  1619. + glob_replace_regex= 0;
  1620. }
  1621. }
  1622.  
  1623. --- 5.1.34/sql/CMakeLists.txt 2009-06-03 23:17:32.000000000 +0200
  1624. +++ 7.0/sql/CMakeLists.txt 2009-06-04 10:35:50.000000000 +0200
  1625. @@ -39,11 +40,16 @@
  1626.  
  1627. ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN -DHAVE_EVENT_SCHEDULER)
  1628.  
  1629. +IF(WITH_NDBCLUSTER_STORAGE_ENGINE)
  1630. + INCLUDE_DIRECTORIES(${NDB_CLIENT_INCLUDES})
  1631. +ENDIF(WITH_NDBCLUSTER_STORAGE_ENGINE)
  1632. +
  1633. ADD_EXECUTABLE(mysqld
  1634. ../sql-common/client.c derror.cc des_key_file.cc
  1635. discover.cc ../libmysql/errmsg.c field.cc field_conv.cc
  1636. filesort.cc gstream.cc
  1637. ha_partition.cc
  1638. + ${NDB_HANDLER_SRC}
  1639. handler.cc hash_filo.cc hash_filo.h
  1640. hostname.cc init.cc item.cc item_buff.cc item_cmpfunc.cc
  1641. item_create.cc item_func.cc item_geofunc.cc item_row.cc
  1642. @@ -119,6 +125,10 @@
  1643. IF(WITH_INNOBASE_STORAGE_ENGINE)
  1644. TARGET_LINK_LIBRARIES(mysqld innobase)
  1645. ENDIF(WITH_INNOBASE_STORAGE_ENGINE)
  1646. +IF(WITH_NDBCLUSTER_STORAGE_ENGINE)
  1647. + TARGET_LINK_LIBRARIES(mysqld ndbclient)
  1648. +ENDIF(WITH_NDBCLUSTER_STORAGE_ENGINE)
  1649. +
  1650.  
  1651. ADD_DEPENDENCIES(mysqld GenError)
  1652.  
  1653. --- 5.1.34/sql/field.cc 2009-06-03 23:17:47.000000000 +0200
  1654. +++ 7.0/sql/field.cc 2009-06-04 10:35:50.000000000 +0200
  1655. @@ -7231,6 +7234,11 @@
  1656. return length_bytes == 1 ? (uint32) *ptr : uint2korr(ptr);
  1657. }
  1658.  
  1659. +uint32 Field_varstring::used_length()
  1660. +{
  1661. + return length_bytes == 1 ? 1 + (uint32) (uchar) *ptr : 2 + uint2korr(ptr);
  1662. +}
  1663. +
  1664. /*
  1665.   Functions to create a packed row.
  1666.   Here the number of length bytes are depending on the given max_length
  1667. @@ -9519,7 +9527,9 @@
  1668.   uint fld_type_modifier, Item *fld_default_value,
  1669.   Item *fld_on_update_value, LEX_STRING *fld_comment,
  1670.   char *fld_change, List<String> *fld_interval_list,
  1671. - CHARSET_INFO *fld_charset, uint fld_geom_type)
  1672. + CHARSET_INFO *fld_charset, uint fld_geom_type,
  1673. + enum ha_storage_media storage_type,
  1674. + enum column_format_type column_format)
  1675.  {
  1676.   uint sign_len, allowed_type_modifier= 0;
  1677.   ulong max_field_charlength= MAX_FIELD_CHARLENGTH;
  1678. @@ -9530,6 +9540,8 @@
  1679.   field_name= fld_name;
  1680.   def= fld_default_value;
  1681.   flags= fld_type_modifier;
  1682. + flags|= (((uint)storage_type & STORAGE_TYPE_MASK) << FIELD_STORAGE_FLAGS);
  1683. + flags|= (((uint)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
  1684.   unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
  1685.   Field::NEXT_NUMBER : Field::NONE);
  1686.   decimals= fld_decimals ? (uint)atoi(fld_decimals) : 0;
  1687. @@ -9841,6 +9853,8 @@
  1688.   }
  1689.   case MYSQL_TYPE_DECIMAL:
  1690.   DBUG_ASSERT(0); /* Was obsolete */
  1691. + default:
  1692. + break;
  1693. }
  1694. /* Remember the value of length */
  1695. char_length= length;
  1696. --- 5.1.34/sql/field.h 2009-06-03 23:17:32.000000000 +0200
  1697. +++ 7.0/sql/field.h 2009-06-04 10:35:50.000000000 +0200
  1698. @@ -186,8 +189,15 @@
  1699.  
  1700. /*
  1701.   data_length() return the "real size" of the data in memory.
  1702. + For varstrings, this does _not_ include the length bytes.
  1703.   */
  1704. virtual uint32 data_length() { return pack_length(); }
  1705. + /*
  1706. + used_length() returns the number of bytes actually used to store the data
  1707. + of the field. So for a varstring it includes both lenght byte(s) and
  1708. + string data, and anything after data_length() bytes are unused.
  1709. + */
  1710. + virtual uint32 used_length() { return pack_length(); }
  1711. virtual uint32 sort_length() const { return pack_length(); }
  1712.  
  1713. /**
  1714. @@ -488,6 +498,19 @@
  1715.   DBUG_ASSERT(0);
  1716.   return GEOM_GEOMETRY;
  1717.   }
  1718. +
  1719. + inline enum ha_storage_media field_storage_type() const
  1720. + {
  1721. + return (enum ha_storage_media)
  1722. + ((flags >> FIELD_STORAGE_FLAGS) & STORAGE_TYPE_MASK);
  1723. + }
  1724. +
  1725. + inline enum column_format_type column_format() const
  1726. + {
  1727. + return (enum column_format_type)
  1728. + ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
  1729. + }
  1730. +
  1731.   /* Hash value */
  1732. virtual void hash(ulong *nr, ulong *nr2);
  1733. friend bool reopen_table(THD *,struct st_table *,bool);
  1734. @@ -1580,6 +1603,7 @@
  1735. uint packed_col_length(const uchar *to, uint length);
  1736. uint max_packed_col_length(uint max_length);
  1737. uint32 data_length();
  1738. + uint32 used_length();
  1739. uint size_of() const { return sizeof(*this); }
  1740. enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
  1741. bool has_charset(void) const
  1742. @@ -2051,6 +2075,18 @@
  1743. { return new (mem_root) Create_field(*this); }
  1744. void create_length_to_internal_length(void);
  1745.  
  1746. + inline enum ha_storage_media field_storage_type() const
  1747. + {
  1748. + return (enum ha_storage_media)
  1749. + ((flags >> FIELD_STORAGE_FLAGS) & STORAGE_TYPE_MASK);
  1750. + }
  1751. +
  1752. + inline enum column_format_type column_format() const
  1753. + {
  1754. + return (enum column_format_type)
  1755. + ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
  1756. + }
  1757. +
  1758. /* Init for a tmp table field. To be extended if need be. */
  1759. void init_for_tmp_table(enum_field_types sql_type_arg,
  1760. uint32 max_length, uint32 decimals,
  1761. @@ -2060,7 +2096,9 @@
  1762. char *decimals, uint type_modifier, Item *default_value,
  1763. Item *on_update_value, LEX_STRING *comment, char *change,
  1764. List<String> *interval_list, CHARSET_INFO *cs,
  1765. - uint uint_geom_type);
  1766. + uint uint_geom_type,
  1767. + enum ha_storage_media storage_type,
  1768. + enum column_format_type column_format);
  1769. };
  1770.  
  1771.  
  1772. --- 5.1.34/sql/ha_partition.cc 2009-06-03 23:17:32.000000000 +0200
  1773. +++ 7.0/sql/ha_partition.cc 2009-06-04 10:35:50.000000000 +0200
  1774. @@ -72,7 +75,7 @@
  1775. TABLE_SHARE *share,
  1776. MEM_ROOT *mem_root);
  1777. static uint partition_flags();
  1778. -static uint alter_table_flags(uint flags);
  1779. +static uint alter_partition_flags();
  1780.  
  1781.  
  1782. static int partition_initialize(void *p)
  1783. @@ -85,7 +88,7 @@
  1784. partition_hton->db_type= DB_TYPE_PARTITION_DB;
  1785. partition_hton->create= partition_create_handler;
  1786. partition_hton->partition_flags= partition_flags;
  1787. - partition_hton->alter_table_flags= alter_table_flags;
  1788. + partition_hton->alter_partition_flags= alter_partition_flags;
  1789. partition_hton->flags= HTON_NOT_USER_SELECTABLE | HTON_HIDDEN;
  1790.  
  1791. return 0;
  1792. @@ -139,7 +142,7 @@
  1793. return HA_CAN_PARTITION;
  1794. }
  1795.  
  1796. -static uint alter_table_flags(uint flags __attribute__((unused)))
  1797. +static uint alter_partition_flags()
  1798. {
  1799. return (HA_PARTITION_FUNCTION_SUPPORTED |
  1800. HA_FAST_CHANGE_PARTITION);
  1801. @@ -3556,10 +3559,10 @@
  1802. }
  1803.  
  1804.  
  1805. -void ha_partition::column_bitmaps_signal()
  1806. +void ha_partition::column_bitmaps_signal(uint sig_type)
  1807. {
  1808. - handler::column_bitmaps_signal();
  1809. - bitmap_union(table->read_set, &m_part_info->full_part_field_set);
  1810. + handler::column_bitmaps_signal(sig_type);
  1811. + bitmap_union(table->read_set, &m_part_info->full_part_field_set);
  1812. }
  1813.  
  1814.  
  1815. @@ -5805,6 +5808,35 @@
  1816. }
  1817.  
  1818.  
  1819. +/*
  1820. + Calculate hash value for KEY partitioning using an array of fields.
  1821. +
  1822. + SYNOPSIS
  1823. + calculate_key_hash_value()
  1824. + field_array An array of the fields in KEY partitioning
  1825. +
  1826. + RETURN VALUE
  1827. + hash_value calculated
  1828. +
  1829. + DESCRIPTION
  1830. + Uses the hash function on the character set of the field. Integer and
  1831. + floating point fields use the binary character set by default.
  1832. +*/
  1833. +
  1834. +uint32 ha_partition::calculate_key_hash_value(Field **field_array)
  1835. +{
  1836. + ulong nr1= 1;
  1837. + ulong nr2= 4;
  1838. +
  1839. + do
  1840. + {
  1841. + Field *field= *field_array;
  1842. + field->hash(&nr1, &nr2);
  1843. + } while (*(++field_array));
  1844. + return (uint32) nr1;
  1845. +}
  1846. +
  1847. +
  1848. /****************************************************************************
  1849.   MODULE print messages
  1850.  ****************************************************************************/
  1851. @@ -5860,89 +5892,6 @@
  1852. /****************************************************************************
  1853.   MODULE handler characteristics
  1854.  ****************************************************************************/
  1855. -/**
  1856. - alter_table_flags must be on handler/table level, not on hton level
  1857. - due to the ha_partition hton does not know what the underlying hton is.
  1858. -*/
  1859. -uint ha_partition::alter_table_flags(uint flags)
  1860. -{
  1861. - DBUG_ENTER("ha_partition::alter_table_flags");
  1862. - DBUG_RETURN(ht->alter_table_flags(flags) |
  1863. - m_file[0]->alter_table_flags(flags));
  1864. -}
  1865. -
  1866. -
  1867. -/**
  1868. - check if copy of data is needed in alter table.
  1869. -*/
  1870. -bool ha_partition::check_if_incompatible_data(HA_CREATE_INFO *create_info,
  1871. - uint table_changes)
  1872. -{
  1873. - handler **file;
  1874. - bool ret= COMPATIBLE_DATA_YES;
  1875. -
  1876. - /*
  1877. - The check for any partitioning related changes have already been done
  1878. - in mysql_alter_table (by fix_partition_func), so it is only up to
  1879. - the underlying handlers.
  1880. - */
  1881. - for (file= m_file; *file; file++)
  1882. - if ((ret= (*file)->check_if_incompatible_data(create_info,
  1883. - table_changes)) !=
  1884. - COMPATIBLE_DATA_YES)
  1885. - break;
  1886. - return ret;
  1887. -}
  1888. -
  1889. -
  1890. -/**
  1891. - Support of fast or online add/drop index
  1892. -*/
  1893. -int ha_partition::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys)
  1894. -{
  1895. - handler **file;
  1896. - int ret= 0;
  1897. -
  1898. - /*
  1899. - There has already been a check in fix_partition_func in mysql_alter_table
  1900. - before this call, which checks for unique/primary key violations of the
  1901. - partitioning function. So no need for extra check here.
  1902. - */
  1903. - for (file= m_file; *file; file++)
  1904. - if ((ret= (*file)->add_index(table_arg, key_info, num_of_keys)))
  1905. - break;
  1906. - return ret;
  1907. -}
  1908. -
  1909. -
  1910. -int ha_partition::prepare_drop_index(TABLE *table_arg, uint *key_num,
  1911. - uint num_of_keys)
  1912. -{
  1913. - handler **file;
  1914. - int ret= 0;
  1915. -
  1916. - /*
  1917. - DROP INDEX does not affect partitioning.
  1918. - */
  1919. - for (file= m_file; *file; file++)
  1920. - if ((ret= (*file)->prepare_drop_index(table_arg, key_num, num_of_keys)))
  1921. - break;
  1922. - return ret;
  1923. -}
  1924. -
  1925. -
  1926. -int ha_partition::final_drop_index(TABLE *table_arg)
  1927. -{
  1928. - handler **file;
  1929. - int ret= HA_ERR_WRONG_COMMAND;
  1930. -
  1931. - for (file= m_file; *file; file++)
  1932. - if ((ret= (*file)->final_drop_index(table_arg)))
  1933. - break;
  1934. - return ret;
  1935. -}
  1936. -
  1937. -
  1938. /*
  1939.   If frm_error() is called then we will use this to to find out what file
  1940.   extensions exist for the storage engine. This is also used by the default
  1941. --- 5.1.34/sql/ha_partition.h 2009-06-03 23:17:32.000000000 +0200
  1942. +++ 7.0/sql/ha_partition.h 2009-06-04 10:35:50.000000000 +0200
  1943. @@ -178,7 +181,7 @@
  1944.   bool auto_increment_safe_stmt_log_lock;
  1945.  public:
  1946.   handler *clone(MEM_ROOT *mem_root);
  1947. - virtual void set_part_info(partition_info *part_info)
  1948. + virtual void set_part_info(partition_info *part_info, bool early)
  1949.   {
  1950.   m_part_info= part_info;
  1951.   m_is_sub_partitioned= part_info->is_sub_partitioned();
  1952. @@ -245,8 +248,6 @@
  1953.   DBUG_RETURN(0);
  1954.   }
  1955.   virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share);
  1956. - virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info,
  1957. - uint table_changes);
  1958.  private:
  1959.   int prepare_for_rename();
  1960.   int copy_partitions(ulonglong * const copied, ulonglong * const deleted);
  1961. @@ -493,7 +494,7 @@
  1962.   int handle_ordered_next(uchar * buf, bool next_same);
  1963.   int handle_ordered_prev(uchar * buf);
  1964.   void return_top_record(uchar * buf);
  1965. - void column_bitmaps_signal();
  1966. + void column_bitmaps_signal(uint sig_type);
  1967.  public:
  1968.   /*
  1969.   -------------------------------------------------------------------------
  1970. @@ -574,6 +575,8 @@
  1971.   underlying handlers must have the same implementation for it to work.
  1972.   */
  1973. virtual uint8 table_cache_type();
  1974. + /* Calculate hash value for PARTITION BY KEY tables. */
  1975. + uint32 calculate_key_hash_value(Field **field_array);
  1976. virtual ha_rows records();
  1977.  
  1978. /*
  1979. @@ -831,11 +834,6 @@
  1980.   return m_file[0]->index_flags(inx, part, all_parts);
  1981.   }
  1982.  
  1983. - /**
  1984. - wrapper function for handlerton alter_table_flags, since
  1985. - the ha_partition_hton cannot know all its capabilities
  1986. - */
  1987. - virtual uint alter_table_flags(uint flags);
  1988. /*
  1989.   extensions of table handler files
  1990.   */
  1991. @@ -1011,14 +1009,14 @@
  1992. -------------------------------------------------------------------------
  1993. MODULE on-line ALTER TABLE
  1994. -------------------------------------------------------------------------
  1995. - These methods are in the handler interface. (used by innodb-plugin)
  1996. - They are used for on-line/fast alter table add/drop index:
  1997. + These methods are in the handler interface but never used (yet)
  1998. + They are to be used by on-line alter table add/drop index:
  1999. + -------------------------------------------------------------------------
  2000. + virtual ulong index_ddl_flags(KEY *wanted_index) const
  2001. + virtual int add_index(TABLE *table_arg,KEY *key_info,uint num_of_keys);
  2002. + virtual int drop_index(TABLE *table_arg,uint *key_num,uint num_of_keys);
  2003. -------------------------------------------------------------------------
  2004. */
  2005. - virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
  2006. - virtual int prepare_drop_index(TABLE *table_arg, uint *key_num,
  2007. - uint num_of_keys);
  2008. - virtual int final_drop_index(TABLE *table_arg);
  2009.  
  2010. /*
  2011.   -------------------------------------------------------------------------
  2012. --- 5.1.34/sql/handler.cc 2009-06-03 23:17:47.000000000 +0200
  2013. +++ 7.0/sql/handler.cc 2009-06-04 10:35:50.000000000 +0200
  2014. @@ -2013,6 +2016,17 @@
  2015.  }
  2016.  
  2017.  
  2018. +/**
  2019. + Get tablespace name from handler
  2020. + Returns the tablespace name associated
  2021. + with the table or NULL if not defined
  2022. +*/
  2023. +const
  2024. +char* handler::get_tablespace_name()
  2025. +{
  2026. + return table->s->tablespace;
  2027. +}
  2028. +
  2029. /** @brief
  2030.   Open database-handler.
  2031.  
  2032. @@ -2431,7 +2445,7 @@
  2033.   rnd_init() call is made as after this, MySQL will not use the bitmap
  2034.   for any program logic checking.
  2035.  */
  2036. -void handler::column_bitmaps_signal()
  2037. +void handler::column_bitmaps_signal(uint sig_type)
  2038. {
  2039. DBUG_ENTER("column_bitmaps_signal");
  2040. DBUG_PRINT("info", ("read_set: 0x%lx write_set: 0x%lx", (long) table->read_set,
  2041. @@ -2468,7 +2482,7 @@
  2042. (void) extra(HA_EXTRA_KEYREAD);
  2043. table->mark_columns_used_by_index_no_reset(table->s->next_number_index,
  2044. table->read_set);
  2045. - column_bitmaps_signal();
  2046. + column_bitmaps_signal(HA_CHANGE_TABLE_READ_BITMAP);
  2047. index_init(table->s->next_number_index, 1);
  2048. if (table->s->next_number_keypart == 0)
  2049. { // Autoincrement at key-start
  2050. @@ -2928,6 +2942,8 @@
  2051. uint handler::get_dup_key(int error)
  2052. {
  2053. DBUG_ENTER("handler::get_dup_key");
  2054. + if (!table || !table->file)
  2055. + DBUG_RETURN((uint) -1);
  2056. table->file->errkey = (uint) -1;
  2057. if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
  2058. error == HA_ERR_FOUND_DUPP_UNIQUE || error == HA_ERR_NULL_IN_SPATIAL ||
  2059. @@ -3526,7 +3542,7 @@
  2060. init_tmp_table_share(thd, &share, db, 0, table_name, path);
  2061. if (open_table_def(thd, &share, 0) ||
  2062. open_table_from_share(thd, &share, "", 0, (uint) READ_ALL, 0, &table,
  2063. - TRUE))
  2064. + OTM_CREATE))
  2065. goto err;
  2066.  
  2067. if (update_create_info)
  2068. @@ -3595,7 +3611,7 @@
  2069. {
  2070. DBUG_RETURN(3);
  2071. }
  2072. - if (open_table_from_share(thd, &share, "" ,0, 0, 0, &table, FALSE))
  2073. + if (open_table_from_share(thd, &share, "" ,0, 0, 0, &table, OTM_OPEN))
  2074. {
  2075. free_table_share(&share);
  2076. DBUG_RETURN(3);
  2077. @@ -3854,7 +3870,7 @@
  2078. DBUG_RETURN(args.err);
  2079. }
  2080.  
  2081. -#ifdef HAVE_NDB_BINLOG
  2082. +#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
  2083. /*
  2084.   TODO: change this into a dynamic struct
  2085.   List<handlerton> does not work as
  2086. @@ -3899,27 +3915,34 @@
  2087.  {
  2088.   hton_list_st hton_list;
  2089.   uint i, sz;
  2090. + int res= 0;
  2091.  
  2092.   hton_list.sz= 0;
  2093.   plugin_foreach(thd, binlog_func_list,
  2094.   MYSQL_STORAGE_ENGINE_PLUGIN, &hton_list);
  2095.  
  2096.   for (i= 0, sz= hton_list.sz; i < sz ; i++)
  2097. - hton_list.hton[i]->binlog_func(hton_list.hton[i], thd, bfn->fn, bfn->arg);
  2098. - return FALSE;
  2099. + res|= hton_list.hton[i]->binlog_func(hton_list.hton[i], thd, bfn->fn, bfn->arg);
  2100. + return res != 0;
  2101.  }
  2102.  
  2103. +#ifdef HAVE_NDB_BINLOG
  2104.  int ha_reset_logs(THD *thd)
  2105.  {
  2106.   binlog_func_st bfn= {BFN_RESET_LOGS, 0};
  2107.   binlog_func_foreach(thd, &bfn);
  2108. + if (thd->main_da.is_error())
  2109. + return 1;
  2110.   return 0;
  2111.  }
  2112.  
  2113. -void ha_reset_slave(THD* thd)
  2114. +int ha_reset_slave(THD* thd)
  2115.  {
  2116.   binlog_func_st bfn= {BFN_RESET_SLAVE, 0};
  2117.   binlog_func_foreach(thd, &bfn);
  2118. + if (thd->main_da.is_error())
  2119. + return 1;
  2120. + return 0;
  2121.  }
  2122.  
  2123.  void ha_binlog_wait(THD* thd)
  2124. @@ -3939,9 +3962,48 @@
  2125.  {
  2126.   binlog_func_st bfn= {BFN_BINLOG_PURGE_FILE, (void *)file};
  2127.   binlog_func_foreach(thd, &bfn);
  2128. + if (thd->main_da.is_error())
  2129. + return 1;
  2130. + return 0;
  2131. +}
  2132. +#endif
  2133. +
  2134. +static int ha_global_schema_lock(THD *thd, int no_queue)
  2135. +{
  2136. + binlog_func_st bfn= {BFN_GLOBAL_SCHEMA_LOCK, (void *)&no_queue};
  2137. + int res= binlog_func_foreach(thd, &bfn);
  2138. + if (res || thd->main_da.is_error())
  2139. + return 1;
  2140. + return 0;
  2141. +}
  2142. +
  2143. +static int ha_global_schema_unlock(THD *thd)
  2144. +{
  2145. + binlog_func_st bfn= {BFN_GLOBAL_SCHEMA_UNLOCK, 0};
  2146. + binlog_func_foreach(thd, &bfn);
  2147. + if (thd->main_da.is_error())
  2148. + return 1;
  2149.   return 0;
  2150.  }
  2151.  
  2152. +Ha_global_schema_lock_guard::Ha_global_schema_lock_guard(THD *thd)
  2153. + : m_thd(thd), m_lock(0)
  2154. +{
  2155. +}
  2156. +
  2157. +Ha_global_schema_lock_guard::~Ha_global_schema_lock_guard()
  2158. +{
  2159. + if (m_lock)
  2160. + ha_global_schema_unlock(m_thd);
  2161. +}
  2162. +
  2163. +int Ha_global_schema_lock_guard::lock(int no_queue)
  2164. +{
  2165. + DBUG_ASSERT(m_lock == 0);
  2166. + m_lock= 1;
  2167. + return ha_global_schema_lock(m_thd, no_queue);
  2168. +}
  2169. +
  2170.  struct binlog_log_query_st
  2171.  {
  2172.   enum_binlog_command binlog_command;
  2173. @@ -4578,9 +4640,9 @@
  2174.  
  2175.   mark_trx_read_write();
  2176.  
  2177. - if (unlikely(error= write_row(buf)))
  2178. + if (unlikely((error= write_row(buf)) != 0))
  2179.   DBUG_RETURN(error);
  2180. - if (unlikely(error= binlog_log_row(table, 0, buf, log_func)))
  2181. + if (unlikely((error= binlog_log_row(table, 0, buf, log_func)) != 0))
  2182.   DBUG_RETURN(error); /* purecov: inspected */
  2183. DBUG_RETURN(0);
  2184. }
  2185. @@ -4599,23 +4661,28 @@
  2186.  
  2187. mark_trx_read_write();
  2188.  
  2189. - if (unlikely(error= update_row(old_data, new_data)))
  2190. + if (unlikely((error= update_row(old_data, new_data)) != 0))
  2191. return error;
  2192. - if (unlikely(error= binlog_log_row(table, old_data, new_data, log_func)))
  2193. + if (unlikely((error= binlog_log_row(table, old_data, new_data, log_func))!=0))
  2194. return error;
  2195. return 0;
  2196. }
  2197.  
  2198. -int handler::ha_delete_row(const uchar *buf)
  2199. +int handler::ha_delete_row(const uchar *buf, bool will_batch)
  2200. {
  2201. int error;
  2202. Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function;
  2203.  
  2204. mark_trx_read_write();
  2205.  
  2206. - if (unlikely(error= delete_row(buf)))
  2207. + if (will_batch)
  2208. + {
  2209. + if (unlikely((error= bulk_delete_row(buf)) != 0))
  2210. + return error;
  2211. + }
  2212. + else if (unlikely((error= delete_row(buf)) != 0))
  2213. return error;
  2214. - if (unlikely(error= binlog_log_row(table, buf, 0, log_func)))
  2215. + if (unlikely((error= binlog_log_row(table, buf, 0, log_func)) != 0))
  2216. return error;
  2217. return 0;
  2218. }
  2219. --- 5.1.34/sql/handler.h 2009-06-03 23:17:47.000000000 +0200
  2220. +++ 7.0/sql/handler.h 2009-06-04 10:35:50.000000000 +0200
  2221. @@ -47,6 +50,61 @@
  2222. #define HA_ADMIN_NEEDS_ALTER -11
  2223. #define HA_ADMIN_NEEDS_CHECK -12
  2224.  
  2225. +/* Bits to show what an alter table will do */
  2226. +#include <sql_bitmap.h>
  2227. +
  2228. +#define HA_MAX_ALTER_FLAGS 40
  2229. +typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
  2230. +
  2231. +#define HA_ADD_INDEX (0)
  2232. +#define HA_DROP_INDEX (1)
  2233. +#define HA_ALTER_INDEX (2)
  2234. +#define HA_RENAME_INDEX (3)
  2235. +#define HA_ADD_UNIQUE_INDEX (4)
  2236. +#define HA_DROP_UNIQUE_INDEX (5)
  2237. +#define HA_ALTER_UNIQUE_INDEX (6)
  2238. +#define HA_RENAME_UNIQUE_INDEX (7)
  2239. +#define HA_ADD_PK_INDEX (8)
  2240. +#define HA_DROP_PK_INDEX (9)
  2241. +#define HA_ALTER_PK_INDEX (10)
  2242. +#define HA_ADD_COLUMN (11)
  2243. +#define HA_DROP_COLUMN (12)
  2244. +#define HA_CHANGE_COLUMN (13)
  2245. +#define HA_ALTER_COLUMN_NAME (14)
  2246. +#define HA_ALTER_COLUMN_TYPE (15)
  2247. +#define HA_ALTER_COLUMN_ORDER (16)
  2248. +#define HA_ALTER_COLUMN_NULLABLE (17)
  2249. +#define HA_COLUMN_DEFAULT_VALUE (18)
  2250. +#define HA_COLUMN_STORAGE (19)
  2251. +#define HA_COLUMN_FORMAT (20)
  2252. +#define HA_ADD_FOREIGN_KEY (21)
  2253. +#define HA_DROP_FOREIGN_KEY (22)
  2254. +#define HA_ALTER_FOREIGN_KEY (23)
  2255. +#define HA_ADD_CONSTRAINT (24)
  2256. +#define HA_ADD_PARTITION (25)
  2257. +#define HA_DROP_PARTITION (26)
  2258. +#define HA_ALTER_PARTITION (27)
  2259. +#define HA_COALESCE_PARTITION (28)
  2260. +#define HA_REORGANIZE_PARTITION (29)
  2261. +#define HA_CHANGE_CHARACTER_SET (30)
  2262. +#define HA_SET_DEFAULT_CHARACTER_SET (31)
  2263. +#define HA_CHANGE_AUTOINCREMENT_VALUE (32)
  2264. +#define HA_ALTER_STORAGE (33)
  2265. +#define HA_ALTER_TABLESPACE (34)
  2266. +#define HA_ALTER_ROW_FORMAT (35)
  2267. +#define HA_RENAME_TABLE (36)
  2268. +#define HA_ALTER_STORAGE_ENGINE (37)
  2269. +#define HA_RECREATE (38)
  2270. +#define HA_ALTER_TABLE_REORG (39)
  2271. +/* Remember to increase HA_MAX_ALTER_FLAGS when adding more flags! */
  2272. +
  2273. +/* Return values for check_if_supported_alter */
  2274. +
  2275. +#define HA_ALTER_ERROR -1
  2276. +#define HA_ALTER_SUPPORTED_WAIT_LOCK 0
  2277. +#define HA_ALTER_SUPPORTED_NO_LOCK 1
  2278. +#define HA_ALTER_NOT_SUPPORTED 2
  2279. +
  2280. /* Bits in table_flags() to show what database can do */
  2281.  
  2282. #define HA_NO_TRANSACTIONS (1 << 0) /* Doesn't support transactions */
  2283. @@ -125,6 +183,8 @@
  2284. #define HA_BINLOG_ROW_CAPABLE (LL(1) << 34)
  2285. #define HA_BINLOG_STMT_CAPABLE (LL(1) << 35)
  2286.  
  2287. +#define HA_ONLINE_ALTER (LL(1) << 36)
  2288. +
  2289. /*
  2290.   Set of all binlog flags. Currently only contain the capabilities
  2291.   flags.
  2292. @@ -140,30 +200,6 @@
  2293.  #define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */
  2294.  
  2295. /*
  2296. - bits in alter_table_flags:
  2297. -*/
  2298. -/*
  2299. - These bits are set if different kinds of indexes can be created
  2300. - off-line without re-create of the table (but with a table lock).
  2301. -*/
  2302. -#define HA_ONLINE_ADD_INDEX_NO_WRITES (1L << 0) /*add index w/lock*/
  2303. -#define HA_ONLINE_DROP_INDEX_NO_WRITES (1L << 1) /*drop index w/lock*/
  2304. -#define HA_ONLINE_ADD_UNIQUE_INDEX_NO_WRITES (1L << 2) /*add unique w/lock*/
  2305. -#define HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES (1L << 3) /*drop uniq. w/lock*/
  2306. -#define HA_ONLINE_ADD_PK_INDEX_NO_WRITES (1L << 4) /*add prim. w/lock*/
  2307. -#define HA_ONLINE_DROP_PK_INDEX_NO_WRITES (1L << 5) /*drop prim. w/lock*/
  2308. -/*
  2309. - These are set if different kinds of indexes can be created on-line
  2310. - (without a table lock). If a handler is capable of one or more of
  2311. - these, it should also set the corresponding *_NO_WRITES bit(s).
  2312. -*/
  2313. -#define HA_ONLINE_ADD_INDEX (1L << 6) /*add index online*/
  2314. -#define HA_ONLINE_DROP_INDEX (1L << 7) /*drop index online*/
  2315. -#define HA_ONLINE_ADD_UNIQUE_INDEX (1L << 8) /*add unique online*/
  2316. -#define HA_ONLINE_DROP_UNIQUE_INDEX (1L << 9) /*drop uniq. online*/
  2317. -#define HA_ONLINE_ADD_PK_INDEX (1L << 10)/*add prim. online*/
  2318. -#define HA_ONLINE_DROP_PK_INDEX (1L << 11)/*drop prim. online*/
  2319. -/*
  2320.   HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
  2321.   supported at all.
  2322.   HA_FAST_CHANGE_PARTITION means that optimised variants of the changes
  2323. @@ -188,9 +224,9 @@
  2324.   the storage engine. A typical engine to support this is NDB (through
  2325.   WL #2498).
  2326.  */
  2327. -#define HA_PARTITION_FUNCTION_SUPPORTED (1L << 12)
  2328. -#define HA_FAST_CHANGE_PARTITION (1L << 13)
  2329. -#define HA_PARTITION_ONE_PHASE (1L << 14)
  2330. +#define HA_PARTITION_FUNCTION_SUPPORTED (1L << 1)
  2331. +#define HA_FAST_CHANGE_PARTITION (1L << 2)
  2332. +#define HA_PARTITION_ONE_PHASE (1L << 3)
  2333.  
  2334. /*
  2335.   Index scan will not return records in rowid order. Not guaranteed to be
  2336. @@ -230,7 +266,7 @@
  2337.  #define HA_BLOCK_LOCK 256 /* unlock when reading some records */
  2338. #define HA_OPEN_TEMPORARY 512
  2339.  
  2340. - /* Some key definitions */
  2341. +/* Some key definitions */
  2342. #define HA_KEY_NULL_LENGTH 1
  2343. #define HA_KEY_BLOB_LENGTH 2
  2344.  
  2345. @@ -282,12 +318,19 @@
  2346. ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
  2347. ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT, ROW_TYPE_PAGE };
  2348.  
  2349. +enum column_format_type { COLUMN_FORMAT_TYPE_NOT_USED= -1,
  2350. + COLUMN_FORMAT_TYPE_DEFAULT= 0,
  2351. + COLUMN_FORMAT_TYPE_FIXED= 1,
  2352. + COLUMN_FORMAT_TYPE_DYNAMIC= 2 };
  2353. +
  2354. enum enum_binlog_func {
  2355. BFN_RESET_LOGS= 1,
  2356. BFN_RESET_SLAVE= 2,
  2357. BFN_BINLOG_WAIT= 3,
  2358. BFN_BINLOG_END= 4,
  2359. - BFN_BINLOG_PURGE_FILE= 5
  2360. + BFN_BINLOG_PURGE_FILE= 5,
  2361. + BFN_GLOBAL_SCHEMA_LOCK= 6,
  2362. + BFN_GLOBAL_SCHEMA_UNLOCK=7
  2363. };
  2364.  
  2365. enum enum_binlog_command {
  2366. @@ -664,7 +707,7 @@
  2367. bool (*flush_logs)(handlerton *hton);
  2368. bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
  2369. uint (*partition_flags)();
  2370. - uint (*alter_table_flags)(uint flags);
  2371. + uint (*alter_partition_flags)();
  2372. int (*alter_tablespace)(handlerton *hton, THD *thd, st_alter_tablespace *ts_info);
  2373. int (*fill_files_table)(handlerton *hton, THD *thd,
  2374. TABLE_LIST *tables,
  2375. @@ -863,7 +906,7 @@
  2376.  
  2377.  
  2378. enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
  2379. - ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
  2380. + ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
  2381.  
  2382.  
  2383. enum ndb_distribution { ND_KEYHASH= 0, ND_LINHASH= 1 };
  2384. @@ -919,10 +962,21 @@
  2385. bool table_existed; /* 1 in create if table existed */
  2386. bool frm_only; /* 1 if no ha_create_table() */
  2387. bool varchar; /* 1 if table has a VARCHAR */
  2388. - enum ha_storage_media storage_media; /* DEFAULT, DISK or MEMORY */
  2389. + enum ha_storage_media default_storage_media; /* DEFAULT, DISK or MEMORY */
  2390. enum ha_choice page_checksum; /* If we have page_checksums */
  2391. } HA_CREATE_INFO;
  2392.  
  2393. +typedef struct st_ha_alter_information
  2394. +{
  2395. + KEY *key_info_buffer;
  2396. + uint key_count;
  2397. + uint index_drop_count;
  2398. + uint *index_drop_buffer;
  2399. + uint index_add_count;
  2400. + uint *index_add_buffer;
  2401. + void *data;
  2402. +} HA_ALTER_INFO;
  2403. +
  2404.  
  2405. typedef struct st_key_create_information
  2406. {
  2407. @@ -1026,6 +1080,7 @@
  2408. ulonglong max_index_file_length;
  2409. ulonglong delete_length; /* Free bytes */
  2410. ulonglong auto_increment_value;
  2411. + ha_rows rows_updated, rows_deleted;
  2412. /*
  2413.   The number of records in the table.
  2414.   0 - means the table has exactly 0 rows
  2415. @@ -1211,7 +1266,7 @@
  2416.   int ha_external_lock(THD *thd, int lock_type);
  2417.   int ha_write_row(uchar * buf);
  2418.   int ha_update_row(const uchar * old_data, uchar * new_data);
  2419. - int ha_delete_row(const uchar * buf);
  2420. + int ha_delete_row(const uchar * buf, bool will_batch= FALSE);
  2421.   void ha_release_auto_increment();
  2422.  
  2423.   int check_collation_compatibility();
  2424. @@ -1330,7 +1385,15 @@
  2425.   a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
  2426.   as there may be several calls to this routine.
  2427.   */
  2428. - virtual void column_bitmaps_signal();
  2429. +
  2430. +#define HA_CHANGE_TABLE_READ_BITMAP 1
  2431. +#define HA_CHANGE_TABLE_WRITE_BITMAP 2
  2432. +#define HA_CHANGE_TABLE_BOTH_BITMAPS 2+1
  2433. +
  2434. +#define HA_COMPLETE_TABLE_READ_BITMAP 4
  2435. +#define HA_COMPLETE_TABLE_WRITE_BITMAP 8
  2436. +#define HA_COMPLETE_TABLE_BOTH_BITMAPS 4+8
  2437. + virtual void column_bitmaps_signal(uint sig_type);
  2438. uint get_index(void) const { return active_index; }
  2439. virtual int close(void)=0;
  2440.  
  2441. @@ -1460,10 +1523,20 @@
  2442. virtual int info(uint)=0; // see my_base.h for full description
  2443. virtual void get_dynamic_partition_info(PARTITION_INFO *stat_info,
  2444. uint part_id);
  2445. + virtual uint32 calculate_key_hash_value(Field **field_array)
  2446. + { DBUG_ASSERT(0); return 0; }
  2447. virtual int extra(enum ha_extra_function operation)
  2448. { return 0; }
  2449. virtual int extra_opt(enum ha_extra_function operation, ulong cache_size)
  2450. { return extra(operation); }
  2451. + /*
  2452. + Informs handler that it is possible to optimise away the real read
  2453. + operation from the handler and instead use a generated read to
  2454. + optimise simple UPDATE's and DELETE's.
  2455. + */
  2456. + virtual bool read_before_write_removal_possible(List<Item> *fields,
  2457. + List<Item> *values)
  2458. + { return FALSE; }
  2459.  
  2460. /**
  2461.   In an UPDATE or DELETE, if the row under the cursor was locked by another
  2462. @@ -1540,8 +1613,8 @@
  2463.   { return FALSE; }
  2464.   virtual char* get_foreign_key_create_info()
  2465.   { return(NULL);} /* gets foreign key create string from InnoDB */
  2466. - virtual char* get_tablespace_name(THD *thd, char *name, uint name_len)
  2467. - { return(NULL);} /* gets tablespace name from handler */
  2468. + /* gets tablespace name from handler */
  2469. + const char* get_tablespace_name();
  2470. /** used in ALTER TABLE; 1 if changing storage engine is allowed */
  2471. virtual bool can_switch_engines() { return 1; }
  2472. /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
  2473. @@ -1574,7 +1647,9 @@
  2474. *no_parts= 0;
  2475. return 0;
  2476. }
  2477. - virtual void set_part_info(partition_info *part_info) {return;}
  2478. + virtual void set_part_info(partition_info *part_info,
  2479. + bool early)
  2480. + {return;}
  2481.  
  2482. virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
  2483.  
  2484. @@ -1613,7 +1688,6 @@
  2485. #define CHF_CREATE_FLAG 0
  2486. #define CHF_DELETE_FLAG 1
  2487. #define CHF_RENAME_FLAG 2
  2488. -#define CHF_INDEX_FLAG 3
  2489.  
  2490.  
  2491. /**
  2492. @@ -1634,8 +1708,8 @@
  2493.   are not attached when this is called from another thread.
  2494.   */
  2495. virtual THR_LOCK_DATA **store_lock(THD *thd,
  2496. - THR_LOCK_DATA **to,
  2497. - enum thr_lock_type lock_type)=0;
  2498. + THR_LOCK_DATA **to,
  2499. + enum thr_lock_type lock_type)=0;
  2500.  
  2501. /** Type of table for caching query */
  2502. virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
  2503. @@ -1726,22 +1800,115 @@
  2504. Pops the top if condition stack, if stack is not empty.
  2505. */
  2506. virtual void cond_pop() { return; };
  2507. + /*
  2508. + Part of old fast alter table, to be depricated
  2509. + */
  2510. virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info,
  2511. - uint table_changes)
  2512. + uint table_changes)
  2513. { return COMPATIBLE_DATA_NO; }
  2514.  
  2515. + /* On-line ALTER TABLE interface */
  2516. +
  2517. + /**
  2518. + Check if a storage engine supports a particular alter table on-line
  2519. +
  2520. + @param altered_table A temporary table show what table is to
  2521. + change to
  2522. + @param create_info Information from the parsing phase about new
  2523. + table properties.
  2524. + @param alter_flags Bitmask that shows what will be changed
  2525. + @param table_changes Shows if table layout has changed (for
  2526. + backwards compatibility with
  2527. + check_if_incompatible_data
  2528. +
  2529. + @retval HA_ALTER_ERROR Unexpected error
  2530. + @retval HA_ALTER_SUPPORTED_WAIT_LOCK Supported, but requires DDL lock
  2531. + @retval HA_ALTER_SUPPORTED_NO_LOCK Supported
  2532. + @retval HA_ALTER_NOT_SUPPORTED Not supported
  2533. +
  2534. + @note
  2535. + The default implementation is implemented to support fast
  2536. + alter table (storage engines that support some changes by
  2537. + just changing the frm file) without any change in the handler
  2538. + implementation.
  2539. + */
  2540. + virtual int check_if_supported_alter(TABLE *altered_table,
  2541. + HA_CREATE_INFO *create_info,
  2542. + HA_ALTER_FLAGS *alter_flags,
  2543. + uint table_changes)
  2544. + {
  2545. + DBUG_ENTER("check_if_supported_alter");
  2546. + if (this->check_if_incompatible_data(create_info, table_changes)
  2547. + == COMPATIBLE_DATA_NO)
  2548. + DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
  2549. + else
  2550. + DBUG_RETURN(HA_ALTER_SUPPORTED_WAIT_LOCK);
  2551. + }
  2552. + /**
  2553. + Tell storage engine to prepare for the on-line alter table (pre-alter)
  2554. +
  2555. + @param thd The thread handle
  2556. + @param altered_table A temporary table show what table is to
  2557. + change to
  2558. + @param alter_info Storage place for data used during phase1
  2559. + and phase2
  2560. + @param alter_flags Bitmask that shows what will be changed
  2561. +
  2562. + @retval 0 OK
  2563. + @retval error error code passed from storage engine
  2564. + */
  2565. + virtual int alter_table_phase1(THD *thd,
  2566. + TABLE *altered_table,
  2567. + HA_CREATE_INFO *create_info,
  2568. + HA_ALTER_INFO *alter_info,
  2569. + HA_ALTER_FLAGS *alter_flags)
  2570. + {
  2571. + return HA_ERR_UNSUPPORTED;
  2572. + }
  2573. + /**
  2574. + Tell storage engine to perform the on-line alter table (alter)
  2575. +
  2576. + @param thd The thread handle
  2577. + @param altered_table A temporary table show what table is to
  2578. + change to
  2579. + @param alter_info Storage place for data used during phase1
  2580. + and phase2
  2581. + @param alter_flags Bitmask that shows what will be changed
  2582. +
  2583. + @retval 0 OK
  2584. + @retval error error code passed from storage engine
  2585. +
  2586. + @note
  2587. + If check_if_supported_alter returns HA_ALTER_SUPPORTED_WAIT_LOCK
  2588. + this call is to be wrapped with a DDL lock. This is currently NOT
  2589. + supported.
  2590. + */
  2591. + virtual int alter_table_phase2(THD *thd,
  2592. + TABLE *altered_table,
  2593. + HA_CREATE_INFO *create_info,
  2594. + HA_ALTER_INFO *alter_info,
  2595. + HA_ALTER_FLAGS *alter_flags)
  2596. + {
  2597. + return HA_ERR_UNSUPPORTED;
  2598. + }
  2599. + /**
  2600. + Tell storage engine that changed frm file is now on disk and table
  2601. + has been re-opened (post-alter)
  2602. +
  2603. + @param thd The thread handle
  2604. + @param table The altered table, re-opened
  2605. + */
  2606. + virtual int alter_table_phase3(THD *thd, TABLE *table)
  2607. + {
  2608. + return HA_ERR_UNSUPPORTED;
  2609. + }
  2610. +
  2611. /**
  2612.   use_hidden_primary_key() is called in case of an update/delete when
  2613.   (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
  2614.   but we don't have a primary key
  2615.   */
  2616. virtual void use_hidden_primary_key();
  2617. - virtual uint alter_table_flags(uint flags)
  2618. - {
  2619. - if (ht->alter_table_flags)
  2620. - return ht->alter_table_flags(flags);
  2621. - return 0;
  2622. - }
  2623.  
  2624. protected:
  2625. /* Service methods for use by storage engines. */
  2626. @@ -1873,6 +2040,22 @@
  2627. DBUG_ASSERT(FALSE);
  2628. return HA_ERR_WRONG_COMMAND;
  2629. }
  2630. + /*
  2631. + This method is similar to delete_row, however the handler doesn't need
  2632. + to execute the delete at this point in time. The handler can be certain
  2633. + that another call to bulk_delete_row will occur OR a call to
  2634. + end_bulk_delete before the set of deletes in this query is concluded.
  2635. +
  2636. + @param record Record to delete
  2637. +
  2638. + @retval 0 Success
  2639. + @retval !=0 Error code
  2640. + */
  2641. + virtual int bulk_delete_row(const uchar *record)
  2642. + {
  2643. + DBUG_ASSERT(FALSE);
  2644. + return HA_ERR_WRONG_COMMAND;
  2645. + }
  2646. /**
  2647.   This is called to delete all rows in a table
  2648.   If the handler don't support this, then this function will
  2649. @@ -1928,9 +2111,6 @@
  2650.   { return HA_ERR_WRONG_COMMAND; }
  2651.  };
  2652.  
  2653. -
  2654. - /* Some extern variables used with handlers */
  2655. -
  2656. extern const char *ha_row_type[];
  2657. extern const char *tx_isolation_names[];
  2658. extern const char *binlog_format_names[];
  2659. @@ -1938,7 +2118,7 @@
  2660. extern TYPELIB myisam_stats_method_typelib;
  2661. extern ulong total_ha, total_ha_2pc;
  2662.  
  2663. - /* Wrapper functions */
  2664. +/* Wrapper functions */
  2665. #define ha_commit(thd) (ha_commit_trans((thd), TRUE))
  2666. #define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
  2667.  
  2668. @@ -1989,7 +2169,7 @@
  2669. int ha_create_table(THD *thd, const char *path,
  2670. const char *db, const char *table_name,
  2671. HA_CREATE_INFO *create_info,
  2672. - bool update_create_info);
  2673. + bool update_create_info);
  2674. int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
  2675. const char *db, const char *alias, bool generate_warning);
  2676.  
  2677. @@ -2043,21 +2223,48 @@
  2678. #define trans_need_2pc(thd, all) ((total_ha_2pc > 1) && \
  2679. !((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
  2680.  
  2681. +#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
  2682. #ifdef HAVE_NDB_BINLOG
  2683. int ha_reset_logs(THD *thd);
  2684. int ha_binlog_index_purge_file(THD *thd, const char *file);
  2685. -void ha_reset_slave(THD *thd);
  2686. +int ha_reset_slave(THD *thd);
  2687. +void ha_binlog_wait(THD *thd);
  2688. +int ha_binlog_end(THD *thd);
  2689. +#else
  2690. +inline int ha_int_dummy() { return 0; }
  2691. +#define ha_reset_logs(a) ha_int_dummy()
  2692. +#define ha_binlog_index_purge_file(a,b) ha_int_dummy()
  2693. +#define ha_reset_slave(a) ha_int_dummy()
  2694. +#define ha_binlog_wait(a) do {} while (0)
  2695. +#define ha_binlog_end(a) do {} while (0)
  2696. +#endif
  2697. void ha_binlog_log_query(THD *thd, handlerton *db_type,
  2698. enum_binlog_command binlog_command,
  2699. const char *query, uint query_length,
  2700. const char *db, const char *table_name);
  2701. -void ha_binlog_wait(THD *thd);
  2702. -int ha_binlog_end(THD *thd);
  2703. +class Ha_global_schema_lock_guard
  2704. +{
  2705. +public:
  2706. + Ha_global_schema_lock_guard(THD *thd);
  2707. + ~Ha_global_schema_lock_guard();
  2708. + int lock(int no_queue= 0);
  2709. +private:
  2710. + THD *m_thd;
  2711. + int m_lock;
  2712. +};
  2713. #else
  2714. -#define ha_reset_logs(a) do {} while (0)
  2715. -#define ha_binlog_index_purge_file(a,b) do {} while (0)
  2716. -#define ha_reset_slave(a) do {} while (0)
  2717. +inline int ha_int_dummy() { return 0; }
  2718. +#define ha_reset_logs(a) ha_int_dummy()
  2719. +#define ha_binlog_index_purge_file(a,b) ha_int_dummy()
  2720. +#define ha_reset_slave(a) ha_int_dummy()
  2721. #define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
  2722. #define ha_binlog_wait(a) do {} while (0)
  2723. #define ha_binlog_end(a) do {} while (0)
  2724. +class Ha_global_schema_lock_guard
  2725. +{
  2726. +public:
  2727. + Ha_global_schema_lock_guard(THD *thd) {}
  2728. + ~Ha_global_schema_lock_guard() {}
  2729. + int lock(int no_queue= 0) { return 0; }
  2730. +};
  2731. #endif
  2732. --- 5.1.34/sql/hostname.cc 2009-06-03 23:17:32.000000000 +0200
  2733. +++ 7.0/sql/hostname.cc 2009-06-04 10:35:50.000000000 +0200
  2734. @@ -34,7 +37,6 @@
  2735. #ifdef HAVE_SYS_UN_H
  2736. #include <sys/un.h>
  2737. #endif
  2738. -#include <netdb.h>
  2739. #include <sys/utsname.h>
  2740. #endif // __WIN__
  2741. #ifdef __cplusplus
  2742. @@ -45,7 +47,7 @@
  2743. class host_entry :public hash_filo_element
  2744. {
  2745. public:
  2746. - char ip[sizeof(((struct in_addr *) 0)->s_addr)];
  2747. + char ip[sizeof(struct sockaddr_storage)];
  2748. uint errors;
  2749. char *hostname;
  2750. };
  2751. @@ -63,7 +65,7 @@
  2752. host_entry tmp;
  2753. uint offset= (uint) ((char*) (&tmp.ip) - (char*) &tmp);
  2754. if (!(hostname_cache=new hash_filo(HOST_CACHE_SIZE, offset,
  2755. - sizeof(struct in_addr),NULL,
  2756. + sizeof(struct sockaddr_storage),NULL,
  2757. (hash_free_key) free,
  2758. &my_charset_bin)))
  2759. return 1;
  2760. @@ -83,20 +85,20 @@
  2761. }
  2762.  
  2763.  
  2764. -static void add_hostname(struct in_addr *in,const char *name)
  2765. +static void add_hostname(struct sockaddr_storage *in,const char *name)
  2766. {
  2767. if (!(specialflag & SPECIAL_NO_HOST_CACHE))
  2768. {
  2769. VOID(pthread_mutex_lock(&hostname_cache->lock));
  2770. host_entry *entry;
  2771. - if (!(entry=(host_entry*) hostname_cache->search((uchar*) &in->s_addr,0)))
  2772. + if (!(entry=(host_entry*) hostname_cache->search((uchar*) in,0)))
  2773. {
  2774. uint length=name ? (uint) strlen(name) : 0;
  2775.  
  2776. if ((entry=(host_entry*) malloc(sizeof(host_entry)+length+1)))
  2777. {
  2778. char *new_name;
  2779. - memcpy_fixed(&entry->ip, &in->s_addr, sizeof(in->s_addr));
  2780. + memcpy_fixed(&entry->ip, in, sizeof(struct sockaddr_storage));
  2781. if (length)
  2782. memcpy(new_name= (char *) (entry+1), name, length+1);
  2783. else
  2784. @@ -111,56 +113,79 @@
  2785. }
  2786.  
  2787.  
  2788. -inline void add_wrong_ip(struct in_addr *in)
  2789. +inline void add_wrong_ip(struct sockaddr_storage *in)
  2790. {
  2791. - add_hostname(in,NullS);
  2792. + add_hostname(in, NullS);
  2793. }
  2794.  
  2795. -void inc_host_errors(struct in_addr *in)
  2796. +void inc_host_errors(struct sockaddr_storage *in)
  2797. {
  2798. VOID(pthread_mutex_lock(&hostname_cache->lock));
  2799. host_entry *entry;
  2800. - if ((entry=(host_entry*) hostname_cache->search((uchar*) &in->s_addr,0)))
  2801. + if ((entry=(host_entry*) hostname_cache->search((uchar*) in,0)))
  2802. entry->errors++;
  2803. VOID(pthread_mutex_unlock(&hostname_cache->lock));
  2804. }
  2805.  
  2806. -void reset_host_errors(struct in_addr *in)
  2807. +void reset_host_errors(struct sockaddr_storage *in)
  2808. {
  2809. VOID(pthread_mutex_lock(&hostname_cache->lock));
  2810. host_entry *entry;
  2811. - if ((entry=(host_entry*) hostname_cache->search((uchar*) &in->s_addr,0)))
  2812. + if ((entry=(host_entry*) hostname_cache->search((uchar*) in,0)))
  2813. entry->errors=0;
  2814. VOID(pthread_mutex_unlock(&hostname_cache->lock));
  2815. }
  2816.  
  2817. -/* Deal with systems that don't defined INADDR_LOOPBACK */
  2818. -#ifndef INADDR_LOOPBACK
  2819. -#define INADDR_LOOPBACK 0x7f000001UL
  2820. -#endif
  2821.  
  2822. -char * ip_to_hostname(struct in_addr *in, uint *errors)
  2823. +char * ip_to_hostname(struct sockaddr_storage *in, int addrLen, uint *errors)
  2824. {
  2825. - uint i;
  2826. + char *name= NULL;
  2827. +
  2828. + struct addrinfo hints,*res_lst= NULL,*t_res;
  2829. + int gxi_error;
  2830. + char hostname_buff[NI_MAXHOST];
  2831. +
  2832. host_entry *entry;
  2833. DBUG_ENTER("ip_to_hostname");
  2834. *errors=0;
  2835.  
  2836. - /* We always treat the loopback address as "localhost". */
  2837. - if (in->s_addr == htonl(INADDR_LOOPBACK)) // is expanded inline by gcc
  2838. + /* Historical comparison for 127.0.0.1 */
  2839. + gxi_error= getnameinfo((struct sockaddr *)in, addrLen,
  2840. + hostname_buff, NI_MAXHOST,
  2841. + NULL, 0, NI_NUMERICHOST);
  2842. + if (gxi_error)
  2843. + {
  2844. + DBUG_PRINT("error",("getnameinfo returned %d", gxi_error));
  2845. + DBUG_RETURN(0);
  2846. + }
  2847. + DBUG_PRINT("info",("resolved: %s", hostname_buff));
  2848. +
  2849. + /* The next three compares are to solve historical solutions with localhost */
  2850. + if (!memcmp(hostname_buff, "127.0.0.1", sizeof("127.0.0.1")))
  2851. + {
  2852. DBUG_RETURN((char *)my_localhost);
  2853. -
  2854. + }
  2855. + if (!memcmp(hostname_buff, "::ffff:127.0.0.1", sizeof("::ffff:127.0.0.1")))
  2856. + {
  2857. + DBUG_RETURN((char *)my_localhost);
  2858. + }
  2859. + if (!memcmp(hostname_buff, "::1", sizeof("::1")))
  2860. + {
  2861. + DBUG_RETURN((char *)my_localhost);
  2862. + }
  2863. +
  2864. /* Check first if we have name in cache */
  2865. if (!(specialflag & SPECIAL_NO_HOST_CACHE))
  2866. {
  2867. VOID(pthread_mutex_lock(&hostname_cache->lock));
  2868. - if ((entry=(host_entry*) hostname_cache->search((uchar*) &in->s_addr,0)))
  2869. + if ((entry=(host_entry*) hostname_cache->search((uchar*) in,0)))
  2870. {
  2871. - char *name;
  2872. - if (!entry->hostname)
  2873. - name=0; // Don't allow connection
  2874. - else
  2875. + if (entry->hostname)
  2876. name=my_strdup(entry->hostname,MYF(0));
  2877. + else
  2878. + name= NULL;
  2879. +
  2880. + DBUG_PRINT("info",("cached data %s", name ? name : "null" ));
  2881. *errors= entry->errors;
  2882. VOID(pthread_mutex_unlock(&hostname_cache->lock));
  2883. DBUG_RETURN(name);
  2884. @@ -168,83 +193,11 @@
  2885. VOID(pthread_mutex_unlock(&hostname_cache->lock));
  2886. }
  2887.  
  2888. - struct hostent *hp, *check;
  2889. - char *name;
  2890. - LINT_INIT(check);
  2891. -#if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
  2892. - char buff[GETHOSTBYADDR_BUFF_SIZE],buff2[GETHOSTBYNAME_BUFF_SIZE];
  2893. - int tmp_errno;
  2894. - struct hostent tmp_hostent, tmp_hostent2;
  2895. -#ifdef HAVE_purify
  2896. - bzero(buff,sizeof(buff)); // Bug in purify
  2897. -#endif
  2898. - if (!(hp=gethostbyaddr_r((char*) in,sizeof(*in),
  2899. - AF_INET,
  2900. - &tmp_hostent,buff,sizeof(buff),&tmp_errno)))
  2901. - {
  2902. - DBUG_PRINT("error",("gethostbyaddr_r returned %d",tmp_errno));
  2903. - return 0;
  2904. - }
  2905. - if (!(check=my_gethostbyname_r(hp->h_name,&tmp_hostent2,buff2,sizeof(buff2),
  2906. - &tmp_errno)))
  2907. - {
  2908. - DBUG_PRINT("error",("gethostbyname_r returned %d",tmp_errno));
  2909. - /*
  2910. - Don't cache responses when the DSN server is down, as otherwise
  2911. - transient DNS failure may leave any number of clients (those
  2912. - that attempted to connect during the outage) unable to connect
  2913. - indefinitely.
  2914. - */
  2915. - if (tmp_errno == HOST_NOT_FOUND || tmp_errno == NO_DATA)
  2916. - add_wrong_ip(in);
  2917. - my_gethostbyname_r_free();
  2918. - DBUG_RETURN(0);
  2919. - }
  2920. - if (!hp->h_name[0])
  2921. - {
  2922. - DBUG_PRINT("error",("Got an empty hostname"));
  2923. - add_wrong_ip(in);
  2924. - my_gethostbyname_r_free();
  2925. - DBUG_RETURN(0); // Don't allow empty hostnames
  2926. - }
  2927. - if (!(name=my_strdup(hp->h_name,MYF(0))))
  2928. - {
  2929. - my_gethostbyname_r_free();
  2930. - DBUG_RETURN(0); // out of memory
  2931. - }
  2932. - my_gethostbyname_r_free();
  2933. -#else
  2934. - VOID(pthread_mutex_lock(&LOCK_hostname));
  2935. - if (!(hp=gethostbyaddr((char*) in,sizeof(*in), AF_INET)))
  2936. - {
  2937. - VOID(pthread_mutex_unlock(&LOCK_hostname));
  2938. - DBUG_PRINT("error",("gethostbyaddr returned %d",errno));
  2939. -
  2940. - if (errno == HOST_NOT_FOUND || errno == NO_DATA)
  2941. - goto add_wrong_ip_and_return;
  2942. - /* Failure, don't cache responce */
  2943. - DBUG_RETURN(0);
  2944. - }
  2945. - if (!hp->h_name[0]) // Don't allow empty hostnames
  2946. - {
  2947. - VOID(pthread_mutex_unlock(&LOCK_hostname));
  2948. - DBUG_PRINT("error",("Got an empty hostname"));
  2949. - goto add_wrong_ip_and_return;
  2950. - }
  2951. - if (!(name=my_strdup(hp->h_name,MYF(0))))
  2952. + if (!(name= my_strdup(hostname_buff,MYF(0))))
  2953. {
  2954. - VOID(pthread_mutex_unlock(&LOCK_hostname));
  2955. - DBUG_RETURN(0); // out of memory
  2956. - }
  2957. - check=gethostbyname(name);
  2958. - VOID(pthread_mutex_unlock(&LOCK_hostname));
  2959. - if (!check)
  2960. - {
  2961. - DBUG_PRINT("error",("gethostbyname returned %d",errno));
  2962. - my_free(name,MYF(0));
  2963. + DBUG_PRINT("error",("out of memory"));
  2964. DBUG_RETURN(0);
  2965. }
  2966. -#endif
  2967.  
  2968. /* Don't accept hostnames that starts with digits because they may be
  2969.   false ip:s */
  2970. @@ -255,24 +208,57 @@
  2971. if (*pos == '.')
  2972. {
  2973. DBUG_PRINT("error",("mysqld doesn't accept hostnames that starts with a number followed by a '.'"));
  2974. - my_free(name,MYF(0));
  2975. goto add_wrong_ip_and_return;
  2976. }
  2977. }
  2978. + DBUG_PRINT("info",("resolved: %s",name));
  2979. +
  2980. + bzero(&hints, sizeof (struct addrinfo));
  2981. + hints.ai_flags= AI_PASSIVE;
  2982. + hints.ai_socktype= SOCK_STREAM;
  2983. + hints.ai_family= AF_UNSPEC;
  2984.  
  2985. - /* Check that 'gethostbyname' returned the used ip */
  2986. - for (i=0; check->h_addr_list[i]; i++)
  2987. + gxi_error= getaddrinfo(hostname_buff, NULL, &hints, &res_lst);
  2988. + if (gxi_error != 0)
  2989. {
  2990. - if (*(uint32*)(check->h_addr_list)[i] == in->s_addr)
  2991. + /*
  2992. + Don't cache responses when the DNS server is down, as otherwise
  2993. + transient DNS failure may leave any number of clients (those
  2994. + that attempted to connect during the outage) unable to connect
  2995. + indefinitely.
  2996. + */
  2997. + DBUG_PRINT("error",("getaddrinfo returned %d", gxi_error));
  2998. +#ifdef EAI_NODATA
  2999. + if (gxi_error == EAI_NODATA )
  3000. +#else
  3001. + if (gxi_error == EAI_NONAME )
  3002. +#endif
  3003. + add_wrong_ip(in);
  3004. +
  3005. + if (res_lst)
  3006. + freeaddrinfo(res_lst);
  3007. +
  3008. + my_free(name, MYF(0));
  3009. + DBUG_RETURN(0);
  3010. + }
  3011. +
  3012. + /* Check that 'getaddrinfo' returned the used ip */
  3013. + for (t_res= res_lst; t_res; t_res=t_res->ai_next)
  3014. + {
  3015. + if (!memcmp(&(t_res->ai_addr), in,
  3016. + sizeof(struct sockaddr_storage) ) )
  3017. {
  3018. add_hostname(in,name);
  3019. + freeaddrinfo(res_lst);
  3020. DBUG_RETURN(name);
  3021. }
  3022. }
  3023. - DBUG_PRINT("error",("Couldn't verify hostname with gethostbyname"));
  3024. - my_free(name,MYF(0));
  3025. +
  3026. + freeaddrinfo(res_lst);
  3027. + DBUG_PRINT("error",("Couldn't verify hostname with getaddrinfo"));
  3028.  
  3029. add_wrong_ip_and_return:
  3030. + my_free(name,MYF(0));
  3031. add_wrong_ip(in);
  3032. DBUG_RETURN(0);
  3033. }
  3034. --- 5.1.34/sql/item_func.cc 2009-06-03 23:17:47.000000000 +0200
  3035. +++ 7.0/sql/item_func.cc 2009-06-04 10:35:50.000000000 +0200
  3036. @@ -4024,6 +4027,8 @@
  3037. case ROW_RESULT:
  3038. DBUG_ASSERT(1); // Impossible
  3039. break;
  3040. + default:
  3041. + break;
  3042. }
  3043. return 0.0; // Impossible
  3044. }
  3045. @@ -4055,6 +4060,8 @@
  3046. case ROW_RESULT:
  3047. DBUG_ASSERT(1); // Impossible
  3048. break;
  3049. + default:
  3050. + break;
  3051. }
  3052. return LL(0); // Impossible
  3053. }
  3054. @@ -4087,6 +4094,8 @@
  3055. case ROW_RESULT:
  3056. DBUG_ASSERT(1); // Impossible
  3057. break;
  3058. + default:
  3059. + break;
  3060. }
  3061. return(str);
  3062. }
  3063. @@ -4114,6 +4123,8 @@
  3064. case ROW_RESULT:
  3065. DBUG_ASSERT(1); // Impossible
  3066. break;
  3067. + default:
  3068. + break;
  3069. }
  3070. return(val);
  3071. }
  3072. --- 5.1.34/sql/lex.h 2009-06-03 23:17:32.000000000 +0200
  3073. +++ 7.0/sql/lex.h 2009-06-04 10:35:50.000000000 +0200
  3074. @@ -203,6 +206,7 @@
  3075. { "FAST", SYM(FAST_SYM)},
  3076. { "FAULTS", SYM(FAULTS_SYM)},
  3077. { "FETCH", SYM(FETCH_SYM)},
  3078. + { "COLUMN_FORMAT", SYM(COLUMN_FORMAT_SYM)},
  3079. { "FIELDS", SYM(COLUMNS)},
  3080. { "FILE", SYM(FILE_SYM)},
  3081. { "FIRST", SYM(FIRST_SYM)},
  3082. @@ -307,6 +311,7 @@
  3083. { "MASTER", SYM(MASTER_SYM)},
  3084. { "MASTER_CONNECT_RETRY", SYM(MASTER_CONNECT_RETRY_SYM)},
  3085. { "MASTER_HOST", SYM(MASTER_HOST_SYM)},
  3086. + { "MASTER_BIND", SYM(MASTER_BIND_SYM)},
  3087. { "MASTER_LOG_FILE", SYM(MASTER_LOG_FILE_SYM)},
  3088. { "MASTER_LOG_POS", SYM(MASTER_LOG_POS_SYM)},
  3089. { "MASTER_PASSWORD", SYM(MASTER_PASSWORD_SYM)},
  3090. @@ -320,6 +325,7 @@
  3091. { "MASTER_SSL_KEY", SYM(MASTER_SSL_KEY_SYM)},
  3092. { "MASTER_SSL_VERIFY_SERVER_CERT", SYM(MASTER_SSL_VERIFY_SERVER_CERT_SYM)},
  3093. { "MASTER_USER", SYM(MASTER_USER_SYM)},
  3094. + { "MASTER_HEARTBEAT_PERIOD", SYM(MASTER_HEARTBEAT_PERIOD_SYM)},
  3095. { "MATCH", SYM(MATCH)},
  3096. { "MAX_CONNECTIONS_PER_HOUR", SYM(MAX_CONNECTIONS_PER_HOUR)},
  3097. { "MAX_QUERIES_PER_HOUR", SYM(MAX_QUERIES_PER_HOUR)},
  3098. @@ -368,10 +374,12 @@
  3099. { "NULL", SYM(NULL_SYM)},
  3100. { "NUMERIC", SYM(NUMERIC_SYM)},
  3101. { "NVARCHAR", SYM(NVARCHAR_SYM)},
  3102. + { "OFFLINE", SYM(OFFLINE_SYM)},
  3103. { "OFFSET", SYM(OFFSET_SYM)},
  3104. { "OLD_PASSWORD", SYM(OLD_PASSWORD)},
  3105. { "ON", SYM(ON)},
  3106. { "ONE", SYM(ONE_SYM)},
  3107. + { "ONLINE", SYM(ONLINE_SYM)},
  3108. { "ONE_SHOT", SYM(ONE_SHOT_SYM)},
  3109. { "OPEN", SYM(OPEN_SYM)},
  3110. { "OPTIMIZE", SYM(OPTIMIZE)},
  3111. --- 5.1.34/sql/log.cc 2009-06-03 23:17:47.000000000 +0200
  3112. +++ 7.0/sql/log.cc 2009-06-04 10:35:50.000000000 +0200
  3113. @@ -2765,7 +2768,11 @@
  3114. const char* save_name;
  3115. DBUG_ENTER("reset_logs");
  3116.  
  3117. - ha_reset_logs(thd);
  3118. + if (ha_reset_logs(thd))
  3119. + {
  3120. + DBUG_RETURN(1);
  3121. + }
  3122. +
  3123. /*
  3124.   We need to get both locks to be sure that no one is trying to
  3125.   write to the index log file.
  3126. @@ -4461,17 +4468,14 @@
  3127.   THD::enter_cond() (see NOTES in sql_class.h).
  3128.  */
  3129.  
  3130. -void MYSQL_BIN_LOG::wait_for_update(THD* thd, bool is_slave)
  3131. +void MYSQL_BIN_LOG::wait_for_update_relay_log(THD* thd)
  3132. {
  3133. const char *old_msg;
  3134. DBUG_ENTER("wait_for_update");
  3135. -
  3136. old_msg= thd->enter_cond(&update_cond, &LOCK_log,
  3137. - is_slave ?
  3138. - "Has read all relay log; waiting for the slave I/O "
  3139. - "thread to update it" :
  3140. - "Has sent all binlog to slave; waiting for binlog "
  3141. - "to be updated");
  3142. + "Slave has read all relay log; "
  3143. + "waiting for the slave I/O "
  3144. + "thread to update it" );
  3145. pthread_cond_wait(&update_cond, &LOCK_log);
  3146. thd->exit_cond(old_msg);
  3147. DBUG_VOID_RETURN;
  3148. @@ -4479,6 +4483,40 @@
  3149.  
  3150.  
  3151. /**
  3152. + Wait until we get a signal that the binary log has been updated.
  3153. + Applies to master only.
  3154. +
  3155. + NOTES
  3156. + @param[in] thd a THD struct
  3157. + @param[in] timeout a pointer to a timespec;
  3158. + NULL means to wait w/o timeout.
  3159. + @retval 0 if got signalled on update
  3160. + @retval non-0 if wait timeout elapsed
  3161. + @note
  3162. + LOCK_log must be taken before calling this function.
  3163. + LOCK_log is being released while the thread is waiting.
  3164. + LOCK_log is released by the caller.
  3165. +*/
  3166. +
  3167. +int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd,
  3168. + const struct timespec *timeout)
  3169. +{
  3170. + int ret= 0;
  3171. + const char* old_msg = thd->proc_info;
  3172. + DBUG_ENTER("wait_for_update_bin_log");
  3173. + old_msg= thd->enter_cond(&update_cond, &LOCK_log,
  3174. + "Master has sent all binlog to slave; "
  3175. + "waiting for binlog to be updated");
  3176. + if (!timeout)
  3177. + pthread_cond_wait(&update_cond, &LOCK_log);
  3178. + else
  3179. + ret= pthread_cond_timedwait(&update_cond, &LOCK_log,
  3180. + const_cast<struct timespec *>(timeout));
  3181. + DBUG_RETURN(ret);
  3182. +}
  3183. +
  3184. +
  3185. +/**
  3186.   Close the log file.
  3187.  
  3188.   @param exiting Bitmask for one or more of the following bits:
  3189. --- 5.1.34/sql/log_event.cc 2009-06-03 23:17:46.000000000 +0200
  3190. +++ 7.0/sql/log_event.cc 2009-06-04 10:35:50.000000000 +0200
  3191. @@ -3516,6 +3519,7 @@
  3192.   post_header_len[UPDATE_ROWS_EVENT-1]=
  3193.   post_header_len[DELETE_ROWS_EVENT-1]= 6;);
  3194.   post_header_len[INCIDENT_EVENT-1]= INCIDENT_HEADER_LEN;
  3195. + post_header_len[HEARTBEAT_LOG_EVENT-1]= 0;
  3196.  
  3197.   // Sanity-check that all post header lengths are initialized.
  3198.   IF_DBUG({
  3199. @@ -7239,6 +7243,28 @@
  3200.   So we call set_time(), like in SBR. Presently it changes nothing.
  3201.   */
  3202. thd->set_time((time_t)when);
  3203. + /*
  3204. + There are a few flags that are replicated with each row event.
  3205. + Make sure to set/clear them before executing the main body of
  3206. + the event.
  3207. + */
  3208. + if (get_flags(NO_FOREIGN_KEY_CHECKS_F))
  3209. + thd->options|= OPTION_NO_FOREIGN_KEY_CHECKS;
  3210. + else
  3211. + thd->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
  3212. +
  3213. + if (get_flags(RELAXED_UNIQUE_CHECKS_F))
  3214. + thd->options|= OPTION_RELAXED_UNIQUE_CHECKS;
  3215. + else
  3216. + thd->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
  3217. +
  3218. + if (slave_allow_batching)
  3219. + thd->options|= OPTION_ALLOW_BATCH;
  3220. + else
  3221. + thd->options&= ~OPTION_ALLOW_BATCH;
  3222. +
  3223. + /* A small test to verify that objects have consistent types */
  3224. + DBUG_ASSERT(sizeof(thd->options) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS));
  3225.  
  3226. /*
  3227.   Now we are in a statement and will stay in a statement until we
  3228. @@ -7373,6 +7399,8 @@
  3229.   */
  3230. if (rli->tables_to_lock && get_flags(STMT_END_F))
  3231. const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
  3232. + /* reset OPTION_ALLOW_BATCH as not affect later events */
  3233. + thd->options&= ~OPTION_ALLOW_BATCH;
  3234.  
  3235. if (error)
  3236. { /* error has occured during the transaction */
  3237. @@ -8699,6 +8727,22 @@
  3238. table->s->reclength) == 0);
  3239.  
  3240. */
  3241. +
  3242. + /*
  3243. + Ndb does not need read before delete/update (and no updates are sent)
  3244. + if primary key specified
  3245. +
  3246. + (Actually uniquekey will also do, but pk will be in each
  3247. + row if table has pk)
  3248. +
  3249. + Also set ignore no key, as we don't really know if row exists...
  3250. + */
  3251. + if (table->file->ht->db_type == DB_TYPE_NDBCLUSTER)
  3252. + {
  3253. + table->file->extra(HA_EXTRA_IGNORE_NO_KEY);
  3254. + DBUG_RETURN(0);
  3255. + }
  3256. +
  3257. DBUG_PRINT("info",("locating record using primary key (position)"));
  3258. int error= table->file->rnd_pos_by_record(table->record[0]);
  3259. if (error)
  3260. @@ -9282,6 +9326,18 @@
  3261. DBUG_RETURN(write_str(file, m_message.str, (uint) m_message.length));
  3262. }
  3263.  
  3264. +#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
  3265. +Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
  3266. + const Format_description_log_event* description_event)
  3267. + :Log_event(buf, description_event)
  3268. +{
  3269. + uint8 header_size= description_event->common_header_len;
  3270. + ident_len = event_len - header_size;
  3271. + set_if_smaller(ident_len,FN_REFLEN-1);
  3272. + log_ident= buf + header_size;
  3273. +}
  3274. +#endif
  3275. +
  3276.  
  3277. #ifdef MYSQL_CLIENT
  3278. /**
  3279. --- 5.1.34/sql/log_event.h 2009-06-03 23:17:32.000000000 +0200
  3280. +++ 7.0/sql/log_event.h 2009-06-04 10:35:50.000000000 +0200
  3281. @@ -250,6 +253,7 @@
  3282.  #define EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN (4 + 4 + 4 + 1)
  3283.  #define EXECUTE_LOAD_QUERY_HEADER_LEN (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN)
  3284.  #define INCIDENT_HEADER_LEN 2
  3285. +#define HEARTBEAT_HEADER_LEN 0
  3286.  /*
  3287.   Max number of possible extra bytes in a replication event compared to a
  3288.   packet (i.e. a query) sent from client to master;
  3289. @@ -575,6 +579,12 @@
  3290.   INCIDENT_EVENT= 26,
  3291.  
  3292.   /*
  3293. + Heartbeat event to be send by master at its idle time
  3294. + to ensure master's online status to slave
  3295. + */
  3296. + HEARTBEAT_LOG_EVENT= 27,
  3297. +
  3298. + /*
  3299.   Add new events here - right above this comment!
  3300.   Existing events (except ENUM_END_EVENT) should never change their numbers
  3301.   */
  3302. @@ -688,6 +698,20 @@
  3303. } PRINT_EVENT_INFO;
  3304. #endif
  3305.  
  3306. +/**
  3307. + the struct aggregates two paramenters that identify an event
  3308. + uniquely in scope of communication of a particular master and slave couple.
  3309. + I.e there can not be 2 events from the same staying connected master which
  3310. + have the same coordinates.
  3311. + @note
  3312. + Such identifier is not yet unique generally as the event originating master
  3313. + is resetable. Also the crashed master can be replaced with some other.
  3314. +*/
  3315. +struct event_coordinates
  3316. +{
  3317. + char * file_name; // binlog file name (directories stripped)
  3318. + my_off_t pos; // event's position in the binlog file
  3319. +};
  3320.  
  3321. /**
  3322.   @class Log_event
  3323. @@ -1732,6 +1756,7 @@
  3324.   int master_host_len;
  3325.   int master_log_len;
  3326.   uint16 master_port;
  3327. + /* TODO add mysql_bind_addr here ? */
  3328.  
  3329. #ifndef MYSQL_CLIENT
  3330. Slave_log_event(THD* thd_arg, Relay_log_info* rli);
  3331. @@ -3917,6 +3942,42 @@
  3332. reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE);
  3333. }
  3334.  
  3335. +#ifndef MYSQL_CLIENT
  3336. +/*****************************************************************************
  3337. +
  3338. + Heartbeat Log Event class
  3339. +
  3340. + Replication event to ensure to slave that master is alive.
  3341. + The event is originated by master's dump thread and sent straight to
  3342. + slave without being logged. Slave itself does not store it in relay log
  3343. + but rather uses a data for immediate checks and throws away the event.
  3344. +
  3345. + Two members of the class log_ident and Log_event::log_pos comprise
  3346. + @see the event_coordinates instance. The coordinates that a heartbeat
  3347. + instance carries correspond to the last event master has sent from
  3348. + its binlog.
  3349. +
  3350. + ****************************************************************************/
  3351. +class Heartbeat_log_event: public Log_event
  3352. +{
  3353. +public:
  3354. + Heartbeat_log_event(const char* buf, uint event_len,
  3355. + const Format_description_log_event* description_event);
  3356. + Log_event_type get_type_code() { return HEARTBEAT_LOG_EVENT; }
  3357. + bool is_valid() const
  3358. + {
  3359. + return (log_ident != NULL &&
  3360. + log_pos >= BIN_LOG_HEADER_SIZE);
  3361. + }
  3362. + const char * get_log_ident() { return log_ident; }
  3363. + uint get_ident_len() { return ident_len; }
  3364. +
  3365. +private:
  3366. + const char* log_ident;
  3367. + uint ident_len;
  3368. +};
  3369. +#endif
  3370. +
  3371. /**
  3372.   @} (end of group Replication)
  3373.  */
  3374. --- 5.1.34/sql/mysql_priv.h 2009-06-03 23:17:47.000000000 +0200
  3375. +++ 7.0/sql/mysql_priv.h 2009-06-04 10:35:50.000000000 +0200
  3376. @@ -254,6 +257,18 @@
  3377. CHARSET_INFO *m_connection_cl;
  3378. };
  3379.  
  3380. +
  3381. +/**
  3382. + Opening modes for open_temporary_table and open_table_from_share
  3383. +*/
  3384. +
  3385. +enum open_table_mode
  3386. +{
  3387. + OTM_OPEN= 0,
  3388. + OTM_CREATE= 1,
  3389. + OTM_ALTER= 2
  3390. +};
  3391. +
  3392. /***************************************************************************
  3393.   Configuration parameters
  3394.  ****************************************************************************/
  3395. @@ -478,7 +493,11 @@
  3396. #define TMP_TABLE_FORCE_MYISAM (ULL(1) << 32)
  3397. #define OPTION_PROFILING (ULL(1) << 33)
  3398.  
  3399. -
  3400. +/*
  3401. + Dont report errors for individual rows,
  3402. + But just report error on commit (or read ofcourse)
  3403. +*/
  3404. +#define OPTION_ALLOW_BATCH (ULL(1) << 33) // THD, intern (slave)
  3405.  
  3406. /**
  3407.   Maximum length of time zone name that we support
  3408. @@ -1143,6 +1162,9 @@
  3409.  void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
  3410.   const uchar *old_buf);
  3411.  
  3412. +void include_partition_fields_in_used_fields(Field **ptr,
  3413. + MY_BITMAP *read_set);
  3414. +
  3415.  bool mysql_backup_table(THD* thd, TABLE_LIST* table_list);
  3416.  bool mysql_restore_table(THD* thd, TABLE_LIST* table_list);
  3417.  
  3418. @@ -1434,6 +1456,8 @@
  3419.  bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
  3420.   char *length, char *decimal,
  3421.   uint type_modifier,
  3422. + enum ha_storage_media storage_type,
  3423. + enum column_format_type column_format,
  3424.   Item *default_value, Item *on_update_value,
  3425.   LEX_STRING *comment,
  3426.   char *change, List<String> *interval_list,
  3427. @@ -1556,8 +1580,9 @@
  3428.  int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
  3429.  int decide_logging_format(THD *thd, TABLE_LIST *tables);
  3430.  TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
  3431. - const char *table_name, bool link_in_list);
  3432. -bool rm_temporary_table(handlerton *base, char *path);
  3433. + const char *table_name, bool link_in_list,
  3434. + open_table_mode open_mode);
  3435. +bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
  3436.  void free_io_cache(TABLE *entry);
  3437.  void intern_close_table(TABLE *entry);
  3438.  bool close_thread_table(THD *thd, TABLE **table_ptr);
  3439. @@ -1742,6 +1767,7 @@
  3440.   LEX_STRING *connect_string,
  3441.   bool have_lock = FALSE);
  3442.  void copy_field_from_tmp_record(Field *field,int offset);
  3443. +bool check_constant_expressions(List<Item> *values);
  3444.  bool fill_record(THD *thd, Field **field, List<Item> &values,
  3445.   bool ignore_errors);
  3446.  bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
  3447. @@ -1804,7 +1830,7 @@
  3448.  int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
  3449.   uint *key_length, uint *keypart);
  3450.  void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
  3451. -void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
  3452. +void key_restore(uchar *to_record, uchar *from_key, const KEY *key_info,
  3453.   uint key_length);
  3454.  bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length);
  3455.  void key_unpack(String *to,TABLE *form,uint index);
  3456. @@ -1925,6 +1951,7 @@
  3457.  extern ulong slow_launch_threads, slow_launch_time;
  3458.  extern ulong table_cache_size, table_def_size;
  3459.  extern ulong max_connections,max_connect_errors, connect_timeout;
  3460. +extern my_bool slave_allow_batching;
  3461.  extern ulong slave_net_timeout, slave_trans_retries;
  3462.  extern uint max_user_connections;
  3463.  extern ulong what_to_log,flush_time;
  3464. @@ -2153,7 +2180,7 @@
  3465.  void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
  3466.  int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
  3467.   uint db_stat, uint prgflag, uint ha_open_flags,
  3468. - TABLE *outparam, bool is_create_table);
  3469. + TABLE *outparam, open_table_mode open_mode);
  3470.  int readfrm(const char *name, uchar **data, size_t *length);
  3471.  int writefrm(const char* name, const uchar* data, size_t len);
  3472.  int closefrm(TABLE *table, bool free_share);
  3473. @@ -2272,9 +2299,9 @@
  3474.  
  3475.  /* from hostname.cc */
  3476. struct in_addr;
  3477. -char * ip_to_hostname(struct in_addr *in,uint *errors);
  3478. -void inc_host_errors(struct in_addr *in);
  3479. -void reset_host_errors(struct in_addr *in);
  3480. +char * ip_to_hostname(struct sockaddr_storage *in, int addrLen, uint *errors);
  3481. +void inc_host_errors(struct sockaddr_storage *in);
  3482. +void reset_host_errors(struct sockaddr_storage *in);
  3483. bool hostname_cache_init();
  3484. void hostname_cache_free();
  3485. void hostname_cache_refresh(void);
  3486. --- 5.1.34/sql/mysqld.cc 2009-06-03 23:17:32.000000000 +0200
  3487. +++ 7.0/sql/mysqld.cc 2009-06-04 10:35:50.000000000 +0200
  3488. @@ -106,7 +109,6 @@
  3489. #ifdef HAVE_SYS_UN_H
  3490. # include <sys/un.h>
  3491. #endif
  3492. -#include <netdb.h>
  3493. #ifdef HAVE_SELECT_H
  3494. # include <select.h>
  3495. #endif
  3496. @@ -380,7 +382,6 @@
  3497. static uint kill_cached_threads, wake_thread;
  3498. static ulong killed_threads, thread_created;
  3499. static ulong max_used_connections;
  3500. -static ulong my_bind_addr; /**< the address we bind to */
  3501. static volatile ulong cached_thread_count= 0;
  3502. static const char *sql_mode_str= "OFF";
  3503. /* Text representation for OPTIMIZER_SWITCH_DEFAULT */
  3504. @@ -442,20 +443,24 @@
  3505. handlerton *partition_hton;
  3506.  
  3507. #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
  3508. -const char *opt_ndbcluster_connectstring= 0;
  3509. -const char *opt_ndb_connectstring= 0;
  3510. -char opt_ndb_constrbuf[1024]= {0};
  3511. -unsigned opt_ndb_constrbuf_len= 0;
  3512. -my_bool opt_ndb_shm, opt_ndb_optimized_node_selection;
  3513. -ulong opt_ndb_cache_check_time;
  3514. -const char *opt_ndb_mgmd;
  3515. -ulong opt_ndb_nodeid;
  3516. +ulong opt_ndb_cache_check_time, opt_ndb_wait_connected;
  3517. +ulong opt_ndb_cluster_connection_pool;
  3518. ulong ndb_extra_logging;
  3519. -#ifdef HAVE_NDB_BINLOG
  3520. -ulong ndb_report_thresh_binlog_epoch_slip;
  3521. -ulong ndb_report_thresh_binlog_mem_usage;
  3522. -#endif
  3523. -
  3524. +ulong ndb_report_thresh_binlog_epoch_slip= 0;
  3525. +ulong ndb_report_thresh_binlog_mem_usage= 0;
  3526. +my_bool ndb_log_binlog_index= FALSE;
  3527. +my_bool opt_ndb_log_update_as_write= FALSE;
  3528. +my_bool opt_ndb_log_updated_only= FALSE;
  3529. +my_bool opt_ndb_log_orig= FALSE;
  3530. +my_bool opt_ndb_log_bin= FALSE;
  3531. +my_bool opt_ndb_log_empty_epochs= FALSE;
  3532. +
  3533. +extern "C" char opt_ndb_constrbuf[1024];
  3534. +extern "C" my_bool opt_ndb_shm;
  3535. +extern "C" const char *opt_ndb_connectstring;
  3536. +extern "C" unsigned opt_ndb_constrbuf_len;
  3537. +extern "C" const char *opt_ndb_mgmd;
  3538. +extern "C" ulong opt_ndb_nodeid;
  3539. extern const char *ndb_distribution_names[];
  3540. extern TYPELIB ndb_distribution_typelib;
  3541. extern const char *opt_ndb_distribution;
  3542. @@ -506,6 +511,7 @@
  3543. ulong slave_net_timeout, slave_trans_retries;
  3544. ulong slave_exec_mode_options;
  3545. const char *slave_exec_mode_str= "STRICT";
  3546. +my_bool slave_allow_batching;
  3547. ulong thread_cache_size=0, thread_pool_size= 0;
  3548. ulong binlog_cache_size=0, max_binlog_cache_size=0;
  3549. ulong query_cache_size=0;
  3550. @@ -859,11 +865,11 @@
  3551. DBUG_PRINT("quit",("Closing sockets"));
  3552. if (!opt_disable_networking )
  3553. {
  3554. - if (ip_sock != INVALID_SOCKET)
  3555. + if (my_socket_valid(ip_sock))
  3556. {
  3557. - (void) shutdown(ip_sock, SHUT_RDWR);
  3558. - (void) closesocket(ip_sock);
  3559. - ip_sock= INVALID_SOCKET;
  3560. + (void) my_shutdown(ip_sock, SHUT_RDWR);
  3561. + (void) my_socket_close(ip_sock);
  3562. + my_socket_invalidate(&ip_sock);
  3563. }
  3564. }
  3565. #ifdef __NT__
  3566. @@ -891,12 +897,12 @@
  3567. }
  3568. #endif
  3569. #ifdef HAVE_SYS_UN_H
  3570. - if (unix_sock != INVALID_SOCKET)
  3571. + if (my_socket_valid(unix_sock))
  3572. {
  3573. - (void) shutdown(unix_sock, SHUT_RDWR);
  3574. - (void) closesocket(unix_sock);
  3575. + (void) my_shutdown(unix_sock, SHUT_RDWR);
  3576. + (void) my_socket_close(unix_sock);
  3577. (void) unlink(mysqld_unix_port);
  3578. - unix_sock= INVALID_SOCKET;
  3579. + my_socket_invalidate(&unix_sock);
  3580. }
  3581. #endif
  3582. end_thr_alarm(0); // Abort old alarms.
  3583. @@ -993,33 +999,33 @@
  3584. DBUG_ENTER("close_server_sock");
  3585. my_socket tmp_sock;
  3586. tmp_sock=ip_sock;
  3587. - if (tmp_sock != INVALID_SOCKET)
  3588. + if (my_socket_valid(tmp_sock))
  3589. {
  3590. - ip_sock=INVALID_SOCKET;
  3591. + my_socket_invalidate(&ip_sock);
  3592. DBUG_PRINT("info",("calling shutdown on TCP/IP socket"));
  3593. - VOID(shutdown(tmp_sock, SHUT_RDWR));
  3594. + VOID(my_shutdown(tmp_sock, SHUT_RDWR));
  3595. #if defined(__NETWARE__)
  3596. /*
  3597.   The following code is disabled for normal systems as it causes MySQL
  3598.   to hang on AIX 4.3 during shutdown
  3599.   */
  3600. DBUG_PRINT("info",("calling closesocket on TCP/IP socket"));
  3601. - VOID(closesocket(tmp_sock));
  3602. + VOID(my_socket_close(tmp_sock));
  3603. #endif
  3604. }
  3605. tmp_sock=unix_sock;
  3606. - if (tmp_sock != INVALID_SOCKET)
  3607. + if (my_socket_valid(tmp_sock))
  3608. {
  3609. - unix_sock=INVALID_SOCKET;
  3610. + my_socket_invalidate(&unix_sock);
  3611. DBUG_PRINT("info",("calling shutdown on unix socket"));
  3612. - VOID(shutdown(tmp_sock, SHUT_RDWR));
  3613. + VOID(my_shutdown(tmp_sock, SHUT_RDWR));
  3614. #if defined(__NETWARE__)
  3615. /*
  3616.   The following code is disabled for normal systems as it may cause MySQL
  3617.   to hang on AIX 4.3 during shutdown
  3618.   */
  3619. DBUG_PRINT("info",("calling closesocket on unix/IP socket"));
  3620. - VOID(closesocket(tmp_sock));
  3621. + VOID(my_socket_close(tmp_sock));
  3622. #endif
  3623. VOID(unlink(mysqld_unix_port));
  3624. }
  3625. @@ -1583,15 +1589,14 @@
  3626.  
  3627. static void network_init(void)
  3628. {
  3629. - struct sockaddr_in IPaddr;
  3630. #ifdef HAVE_SYS_UN_H
  3631. struct sockaddr_un UNIXaddr;
  3632. #endif
  3633. - int arg=1;
  3634. int ret;
  3635. uint waited;
  3636. uint this_wait;
  3637. uint retry;
  3638. + char port_buf[NI_MAXSERV];
  3639. DBUG_ENTER("network_init");
  3640. LINT_INIT(ret);
  3641.  
  3642. @@ -1602,26 +1607,61 @@
  3643.  
  3644. if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
  3645. {
  3646. + struct addrinfo *addrlist, *addr;
  3647. + struct addrinfo hints;
  3648. + int error;
  3649. DBUG_PRINT("general",("IP Socket is %d",mysqld_port));
  3650. - ip_sock = socket(AF_INET, SOCK_STREAM, 0);
  3651. - if (ip_sock == INVALID_SOCKET)
  3652. +
  3653. + bzero(&hints, sizeof (hints));
  3654. + hints.ai_flags = AI_PASSIVE;
  3655. + hints.ai_socktype = SOCK_STREAM;
  3656. + hints.ai_family= AF_UNSPEC;
  3657. +
  3658. + my_snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
  3659. + error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &addrlist);
  3660. + if (error != 0)
  3661. + {
  3662. + DBUG_PRINT("error",("Got error: %d from getaddrinfo()", error));
  3663. + sql_perror(ER(ER_IPSOCK_ERROR)); /* purecov: tested */
  3664. + unireg_abort(1); /* purecov: tested */
  3665. + }
  3666. +
  3667. + for (addr = addrlist; addr != NULL; addr = addr->ai_next)
  3668. + {
  3669. + ip_sock= my_socket_create(addr->ai_family, addr->ai_socktype,
  3670. + addr->ai_protocol);
  3671. + if (my_socket_valid(ip_sock))
  3672. + break;
  3673. + }
  3674. +
  3675. + if (!my_socket_valid(ip_sock))
  3676. {
  3677. DBUG_PRINT("error",("Got error: %d from socket()",socket_errno));
  3678. sql_perror(ER(ER_IPSOCK_ERROR)); /* purecov: tested */
  3679. unireg_abort(1); /* purecov: tested */
  3680. }
  3681. - bzero((char*) &IPaddr, sizeof(IPaddr));
  3682. - IPaddr.sin_family = AF_INET;
  3683. - IPaddr.sin_addr.s_addr = my_bind_addr;
  3684. - IPaddr.sin_port = (unsigned short) htons((unsigned short) mysqld_port);
  3685.  
  3686. #ifndef __WIN__
  3687. /*
  3688.   We should not use SO_REUSEADDR on windows as this would enable a
  3689.   user to open two mysqld servers with the same TCP/IP port.
  3690.   */
  3691. - (void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg));
  3692. + my_socket_reuseaddr(ip_sock, true);
  3693. #endif /* __WIN__ */
  3694. +#ifdef IPV6_V6ONLY
  3695. + /*
  3696. + For interoperability with older clients, IPv6 socket should
  3697. + listen on both IPv6 and IPv4 wildcard addresses.
  3698. + Turn off IPV6_V6ONLY option.
  3699. + */
  3700. + if (addr->ai_family == AF_INET6)
  3701. + {
  3702. + int enable= 0;
  3703. + DBUG_PRINT("info",("Clearing IPV6_ONLY socket option"));
  3704. + my_setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY,
  3705. + &enable, sizeof(enable));
  3706. + }
  3707. +#endif
  3708. /*
  3709.   Sometimes the port is not released fast enough when stopping and
  3710.   restarting the server. This happens quite often with the test suite
  3711. @@ -1632,8 +1672,7 @@
  3712.   */
  3713. for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
  3714. {
  3715. - if (((ret= bind(ip_sock, my_reinterpret_cast(struct sockaddr *) (&IPaddr),
  3716. - sizeof(IPaddr))) >= 0) ||
  3717. + if (((ret= my_bind(ip_sock, addr->ai_addr, addr->ai_addrlen)) >= 0 ) ||
  3718. (socket_errno != SOCKET_EADDRINUSE) ||
  3719. (waited >= mysqld_port_timeout))
  3720. break;
  3721. @@ -1641,6 +1680,7 @@
  3722. this_wait= retry * retry / 3 + 1;
  3723. sleep(this_wait);
  3724. }
  3725. + freeaddrinfo(addrlist);
  3726. if (ret < 0)
  3727. {
  3728. DBUG_PRINT("error",("Got error: %d from bind",socket_errno));
  3729. @@ -1648,7 +1688,7 @@
  3730. sql_print_error("Do you already have another mysqld server running on port: %d ?",mysqld_port);
  3731. unireg_abort(1);
  3732. }
  3733. - if (listen(ip_sock,(int) back_log) < 0)
  3734. + if (my_listen(ip_sock,(int) back_log) < 0)
  3735. {
  3736. sql_perror("Can't start server: listen() on TCP/IP port");
  3737. sql_print_error("listen() on TCP/IP failed with error %d",
  3738. @@ -1720,7 +1760,8 @@
  3739. (uint) sizeof(UNIXaddr.sun_path) - 1, mysqld_unix_port);
  3740. unireg_abort(1);
  3741. }
  3742. - if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
  3743. + unix_sock= my_socket_create(AF_UNIX, SOCK_STREAM, 0);
  3744. + if (!my_socket_valid(unix_sock))
  3745. {
  3746. sql_perror("Can't start server : UNIX Socket "); /* purecov: inspected */
  3747. unireg_abort(1); /* purecov: inspected */
  3748. @@ -1729,10 +1770,9 @@
  3749. UNIXaddr.sun_family = AF_UNIX;
  3750. strmov(UNIXaddr.sun_path, mysqld_unix_port);
  3751. (void) unlink(mysqld_unix_port);
  3752. - (void) setsockopt(unix_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,
  3753. - sizeof(arg));
  3754. + my_socket_reuseaddr(unix_sock, true);
  3755. umask(0);
  3756. - if (bind(unix_sock, my_reinterpret_cast(struct sockaddr *) (&UNIXaddr),
  3757. + if (my_bind(unix_sock, my_reinterpret_cast(struct sockaddr *) (&UNIXaddr),
  3758. sizeof(UNIXaddr)) < 0)
  3759. {
  3760. sql_perror("Can't start server : Bind on unix socket"); /* purecov: tested */
  3761. @@ -1743,7 +1783,7 @@
  3762. #if defined(S_IFSOCK) && defined(SECURE_SOCKETS)
  3763. (void) chmod(mysqld_unix_port,S_IFSOCK); /* Fix solaris 2.6 bug */
  3764. #endif
  3765. - if (listen(unix_sock,(int) back_log) < 0)
  3766. + if (my_listen(unix_sock,(int) back_log) < 0)
  3767. sql_print_warning("listen() on Unix socket failed with error %d",
  3768. socket_errno);
  3769. }
  3770. @@ -3814,12 +3854,12 @@
  3771. }
  3772. else
  3773. {
  3774. - global_system_variables.binlog_format= BINLOG_FORMAT_STMT;
  3775. + global_system_variables.binlog_format= BINLOG_FORMAT_MIXED;
  3776. }
  3777. }
  3778. else
  3779. if (opt_binlog_format_id == BINLOG_FORMAT_UNSPEC)
  3780. - global_system_variables.binlog_format= BINLOG_FORMAT_STMT;
  3781. + global_system_variables.binlog_format= BINLOG_FORMAT_MIXED;
  3782. else
  3783. {
  3784. DBUG_ASSERT(global_system_variables.binlog_format != BINLOG_FORMAT_UNSPEC);
  3785. @@ -4391,7 +4431,7 @@
  3786. if (!opt_bootstrap)
  3787. (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
  3788.  
  3789. - if (unix_sock != INVALID_SOCKET)
  3790. + if (my_socket_valid(unix_sock))
  3791. unlink(mysqld_unix_port);
  3792. exit(1);
  3793. }
  3794. @@ -4442,7 +4482,7 @@
  3795. unireg_abort(1);
  3796.  
  3797. sql_print_information(ER(ER_STARTUP),my_progname,server_version,
  3798. - ((unix_sock == INVALID_SOCKET) ? (char*) ""
  3799. + ((!my_socket_valid(unix_sock)) ? (char*) ""
  3800. : mysqld_unix_port),
  3801. mysqld_port,
  3802. MYSQL_COMPILATION_COMMENT);
  3803. @@ -4911,9 +4951,9 @@
  3804. /* hack to get around signals ignored in syscalls for problem OS's */
  3805. if (
  3806. #if !defined(__NETWARE__)
  3807. - unix_sock == INVALID_SOCKET ||
  3808. + !my_socket_valid(unix_sock) ||
  3809. #endif
  3810. - (!opt_disable_networking && ip_sock == INVALID_SOCKET))
  3811. + (!opt_disable_networking && !my_socket_valid(ip_sock)))
  3812. {
  3813. select_thread_in_use = 0;
  3814. /* The following call will never return */
  3815. @@ -4932,31 +4972,27 @@
  3816. {
  3817. my_socket sock,new_sock;
  3818. uint error_count=0;
  3819. - uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
  3820. + int max_used_connection= 0;
  3821. fd_set readFDs,clientFDs;
  3822. THD *thd;
  3823. - struct sockaddr_in cAddr;
  3824. - int ip_flags=0,socket_flags=0,flags;
  3825. + struct sockaddr_storage cAddr;
  3826. st_vio *vio_tmp;
  3827. DBUG_ENTER("handle_connections_sockets");
  3828.  
  3829. - LINT_INIT(new_sock);
  3830. + my_socket_invalidate(&new_sock);
  3831. +
  3832. + max_used_connection= my_socket_nfds(ip_sock, max_used_connection);
  3833. + max_used_connection= my_socket_nfds(unix_sock, max_used_connection);
  3834.  
  3835. (void) my_pthread_getprio(pthread_self()); // For debugging
  3836.  
  3837. FD_ZERO(&clientFDs);
  3838. - if (ip_sock != INVALID_SOCKET)
  3839. + if (my_socket_valid(ip_sock))
  3840. {
  3841. - FD_SET(ip_sock,&clientFDs);
  3842. -#ifdef HAVE_FCNTL
  3843. - ip_flags = fcntl(ip_sock, F_GETFL, 0);
  3844. -#endif
  3845. + my_FD_SET(ip_sock,&clientFDs);
  3846. }
  3847. #ifdef HAVE_SYS_UN_H
  3848. - FD_SET(unix_sock,&clientFDs);
  3849. -#ifdef HAVE_FCNTL
  3850. - socket_flags=fcntl(unix_sock, F_GETFL, 0);
  3851. -#endif
  3852. + my_FD_SET(unix_sock,&clientFDs);
  3853. #endif
  3854.  
  3855. DBUG_PRINT("general",("Waiting for connections."));
  3856. @@ -4965,10 +5001,10 @@
  3857. {
  3858. readFDs=clientFDs;
  3859. #ifdef HPUX10
  3860. - if (select(max_used_connection,(int*) &readFDs,0,0,0) < 0)
  3861. + if (select(max_used_connection+1,(int*) &readFDs,0,0,0) < 0)
  3862. continue;
  3863. #else
  3864. - if (select((int) max_used_connection,&readFDs,0,0,0) < 0)
  3865. + if (select((int) max_used_connection+1,&readFDs,0,0,0) < 0)
  3866. {
  3867. if (socket_errno != SOCKET_EINTR)
  3868. {
  3869. @@ -4987,41 +5023,35 @@
  3870.  
  3871. /* Is this a new connection request ? */
  3872. #ifdef HAVE_SYS_UN_H
  3873. - if (FD_ISSET(unix_sock,&readFDs))
  3874. + if (my_FD_ISSET(unix_sock,&readFDs))
  3875. {
  3876. sock = unix_sock;
  3877. - flags= socket_flags;
  3878. }
  3879. else
  3880. #endif
  3881. {
  3882. sock = ip_sock;
  3883. - flags= ip_flags;
  3884. }
  3885.  
  3886. #if !defined(NO_FCNTL_NONBLOCK)
  3887. if (!(test_flags & TEST_BLOCKING))
  3888. {
  3889. -#if defined(O_NONBLOCK)
  3890. - fcntl(sock, F_SETFL, flags | O_NONBLOCK);
  3891. -#elif defined(O_NDELAY)
  3892. - fcntl(sock, F_SETFL, flags | O_NDELAY);
  3893. -#endif
  3894. + my_socket_nonblock(sock, true);
  3895. }
  3896. #endif /* NO_FCNTL_NONBLOCK */
  3897. for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
  3898. {
  3899. - size_socket length=sizeof(struct sockaddr_in);
  3900. - new_sock = accept(sock, my_reinterpret_cast(struct sockaddr *) (&cAddr),
  3901. - &length);
  3902. + size_socket length=sizeof(struct sockaddr_storage);
  3903. + new_sock= my_accept(sock, my_reinterpret_cast(struct sockaddr *) (&cAddr),
  3904. + &length);
  3905. #ifdef __NETWARE__
  3906. // TODO: temporary fix, waiting for TCP/IP fix - DEFECT000303149
  3907. - if ((new_sock == INVALID_SOCKET) && (socket_errno == EINVAL))
  3908. + if ((!my_socket_valid(new_sock)) && (socket_errno == EINVAL))
  3909. {
  3910. kill_server(SIGTERM);
  3911. }
  3912. #endif
  3913. - if (new_sock != INVALID_SOCKET ||
  3914. + if (my_socket_valid(new_sock) ||
  3915. (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
  3916. break;
  3917. MAYBE_BROKEN_SYSCALL;
  3918. @@ -5029,15 +5059,15 @@
  3919. if (!(test_flags & TEST_BLOCKING))
  3920. {
  3921. if (retry == MAX_ACCEPT_RETRY - 1)
  3922. - fcntl(sock, F_SETFL, flags); // Try without O_NONBLOCK
  3923. + my_socket_nonblock(sock, false);
  3924. }
  3925. #endif
  3926. }
  3927. #if !defined(NO_FCNTL_NONBLOCK)
  3928. if (!(test_flags & TEST_BLOCKING))
  3929. - fcntl(sock, F_SETFL, flags);
  3930. + my_socket_nonblock(sock, false);
  3931. #endif
  3932. - if (new_sock == INVALID_SOCKET)
  3933. + if (!my_socket_valid(new_sock))
  3934. {
  3935. if ((error_count++ & 255) == 0) // This can happen often
  3936. sql_perror("Error in accept");
  3937. @@ -5049,7 +5079,7 @@
  3938.  
  3939. #ifdef HAVE_LIBWRAP
  3940. {
  3941. - if (sock == ip_sock)
  3942. + if (my_socket_equal(sock, ip_sock))
  3943. {
  3944. struct request_info req;
  3945. signal(SIGCHLD, SIG_DFL);
  3946. @@ -5074,8 +5104,8 @@
  3947. if (req.sink)
  3948. ((void (*)(int))req.sink)(req.fd);
  3949.  
  3950. - (void) shutdown(new_sock, SHUT_RDWR);
  3951. - (void) closesocket(new_sock);
  3952. + (void) my_shutdown(new_sock, SHUT_RDWR);
  3953. + (void) my_socket_close(new_sock);
  3954. continue;
  3955. }
  3956. }
  3957. @@ -5083,16 +5113,14 @@
  3958. #endif /* HAVE_LIBWRAP */
  3959.  
  3960. {<