]> git.pld-linux.org Git - packages/percona-server.git/blob - mysql-5.7-sphinx.patch
- up to 5.7.24-27
[packages/percona-server.git] / mysql-5.7-sphinx.patch
1 From 8bc97078153cfae322a36151143f1a06196730d7 Mon Sep 17 00:00:00 2001
2 From: Adrian Nuta <adriannuta@gmail.com>
3 Date: Tue, 27 Sep 2016 16:41:36 +0300
4 Subject: [PATCH] sphinxse patches for mariadb 10.1 and mysql 5.7
5
6 ---
7  mysqlse/ha_sphinx.cc | 170 +++++++++++++++++++++++++++++++++++++++++----------
8  mysqlse/ha_sphinx.h  |  30 ++++++---
9  2 files changed, 161 insertions(+), 39 deletions(-)
10
11 diff --git a/mysqlse/ha_sphinx.cc b/mysqlse/ha_sphinx.cc
12 index 9b0c3a8e..080f7ce0 100644
13 --- a/mysqlse/ha_sphinx.cc
14 +++ b/mysqlse/ha_sphinx.cc
15 @@ -34,13 +34,37 @@
16  #include "../mysql_priv.h"
17  #endif
18  
19 +#if !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID>=50709
20 +#include "item_timefunc.h"
21 +#define sphinx_append push_back
22 +#define sphinx_array std::vector
23 +#define sphinx_elements size
24 +#if defined(_WIN32)
25 +#define __WIN__ _WIN32
26 +#define pthread_mutex_init(A,B)  (InitializeCriticalSection(A),0)
27 +#define pthread_mutex_lock(A)   (EnterCriticalSection(A),0)
28 +#define pthread_mutex_unlock(A)  (LeaveCriticalSection(A), 0)
29 +#define pthread_mutex_destroy(A) (DeleteCriticalSection(A), 0)
30 +#define in_addr_t uint32
31 +#include <winsock2.h>
32 +#endif
33 +#else
34 +#define sphinx_append append
35 +#define sphinx_array Dynamic_array
36 +#define sphinx_elements elements
37 +#endif
38 +
39  #include <mysys_err.h>
40  #include <my_sys.h>
41  #include <mysql.h> // include client for INSERT table (sort of redoing federated..)
42  
43  #ifndef __WIN__
44         // UNIX-specific
45 -       #include <my_net.h>
46 +       #if  !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID>=50709
47 +               #include <arpa/inet.h>
48 +       #else
49 +               #include <my_net.h>
50 +       #endif
51         #include <netdb.h>
52         #include <sys/un.h>
53  
54 @@ -286,6 +310,12 @@ inline void SPH_DEBUG ( const char *, ... ) {}
55  #define SafeDelete(_arg)               { if ( _arg ) delete ( _arg );          (_arg) = NULL; }
56  #define SafeDeleteArray(_arg)  { if ( _arg ) delete [] ( _arg );       (_arg) = NULL; }
57  
58 +#if  !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID>=50709
59 +#ifdef __WIN__
60 +typedef native_mutex_t pthread_mutex_t;
61 +#endif
62 +#endif
63 +
64  //////////////////////////////////////////////////////////////////////////////
65  
66  /// per-table structure that will be shared among all open Sphinx SE handlers
67 @@ -602,10 +632,10 @@ struct CSphSEQuery
68                 };
69                 char *                                          m_sName; ///< points to query buffer
70                 int                                                     m_iType;
71 -               Dynamic_array<ulonglong>        m_dIds;
72 -               Dynamic_array<Value_t>          m_dValues;
73 +               sphinx_array<ulonglong> m_dIds;
74 +               sphinx_array<Value_t>           m_dValues;
75         };
76 -       Dynamic_array<Override_t *> m_dOverrides;
77 +       sphinx_array<Override_t *> m_dOverrides;
78  
79  public:
80         char                    m_sParseError[256];
81 @@ -634,10 +664,10 @@ struct CSphSEQuery
82         void                    SendString ( const char * v )   { int iLen = strlen(v); SendDword(iLen); SendBytes ( v, iLen ); }
83         void                    SendFloat ( float v )                   { SendDword ( sphF2DW(v) ); }
84  };
85 -
86 +#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
87  template int CSphSEQuery::ParseArray<uint32> ( uint32 **, const char * );
88  template int CSphSEQuery::ParseArray<longlong> ( longlong **, const char * );
89 -
90 +#endif
91  //////////////////////////////////////////////////////////////////////////////
92  
93  #if MYSQL_VERSION_ID>50100
94 @@ -733,13 +763,21 @@ static int sphinx_init_func ( void * p )
95         {
96                 sphinx_init = 1;
97                 void ( pthread_mutex_init ( &sphinx_mutex, MY_MUTEX_INIT_FAST ) );
98 +               #if  !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50709
99 +               sphinx_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0,
100 +                       sphinx_get_key, 0, 0, 0 );
101 +               #else
102                 sphinx_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0,
103                         sphinx_get_key, 0, 0 );
104 -
105 +               #endif
106                 #if MYSQL_VERSION_ID > 50100
107                 handlerton * hton = (handlerton*) p;
108                 hton->state = SHOW_OPTION_YES;
109 +               #if  !defined(MARIADB_BASE_VERSION)
110                 hton->db_type = DB_TYPE_FIRST_DYNAMIC;
111 +               #else
112 +               hton->db_type = DB_TYPE_AUTOASSIGN;
113 +               #endif
114                 hton->create = sphinx_create_handler;
115                 hton->close_connection = sphinx_close_connection;
116                 hton->show_status = sphinx_show_status;
117 @@ -855,10 +893,15 @@ bool sphinx_show_status ( THD * thd )
118                 SPH_RET(TRUE);
119         }
120         CSphTLS * pTls = (CSphTLS*) thd->ha_data[sphinx_hton.slot];
121 -
122 +       #ifndef MARIADB_BASE_VERSION
123         field_list.push_back ( new Item_empty_string ( "Type", 10 ) );
124         field_list.push_back ( new Item_empty_string ( "Name", FN_REFLEN ) );
125         field_list.push_back ( new Item_empty_string ( "Status", 10 ) );
126 +       #else
127 +       field_list.push_back ( new Item_empty_string ( thd, "Type", 10 ) );
128 +       field_list.push_back ( new Item_empty_string ( thd, "Name", FN_REFLEN ) );
129 +       field_list.push_back ( new Item_empty_string ( thd, "Status", 10 ) );
130 +       #endif
131         if ( protocol->send_fields ( &field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF ) )
132                 SPH_RET(TRUE);
133  
134 @@ -1321,7 +1364,7 @@ CSphSEQuery::~CSphSEQuery ()
135         SafeDeleteArray ( m_sQueryBuffer );
136         SafeDeleteArray ( m_pWeights );
137         SafeDeleteArray ( m_pBuf );
138 -       for ( int i=0; i<m_dOverrides.elements(); i++ )
139 +       for ( int i=0; i<m_dOverrides.sphinx_elements(); i++ )
140                 SafeDelete ( m_dOverrides.at(i) );
141         SPH_VOID_RET();
142  }
143 @@ -1412,6 +1455,15 @@ static bool myismagic ( char c )
144         return c=='@';
145  }
146  
147 +static bool myisjson ( char c )
148 +{
149 +       return
150 +               c=='.' ||
151 +               c=='[' ||
152 +               c==']';
153 +}
154 +
155 +
156  
157  bool CSphSEQuery::ParseField ( char * sField )
158  {
159 @@ -1623,7 +1675,7 @@ bool CSphSEQuery::ParseField ( char * sField )
160                                 break;
161  
162                         tFilter.m_sAttrName = sValue;
163 -                       while ( (*sValue) && ( myisattr(*sValue) || myismagic(*sValue) ) )
164 +                       while ( (*sValue) && ( myisattr(*sValue) || myismagic(*sValue) ) || myisjson(*sValue)  )
165                                 sValue++;
166                         if ( !*sValue )
167                                 break;
168 @@ -1789,7 +1841,7 @@ bool CSphSEQuery::ParseField ( char * sField )
169                                 pOverride = new CSphSEQuery::Override_t;
170                                 pOverride->m_sName = chop(sName);
171                                 pOverride->m_iType = iType;
172 -                               m_dOverrides.append ( pOverride );
173 +                               m_dOverrides.sphinx_append ( pOverride );
174                         }
175  
176                         ulonglong uId = strtoull ( sId, NULL, 10 );
177 @@ -1801,8 +1853,8 @@ bool CSphSEQuery::ParseField ( char * sField )
178                         else
179                                 tValue.m_uValue = (uint32)strtoul ( sValue, NULL, 10 );
180  
181 -                       pOverride->m_dIds.append ( uId );
182 -                       pOverride->m_dValues.append ( tValue );
183 +                       pOverride->m_dIds.sphinx_append ( uId );
184 +                       pOverride->m_dValues.sphinx_append ( tValue );
185                 }
186  
187                 if ( !pOverride )
188 @@ -1906,11 +1958,11 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
189                 iReqSize += 8 + strlen(m_sFieldWeight[i] );
190         // overrides
191         iReqSize += 4;
192 -       for ( int i=0; i<m_dOverrides.elements(); i++ )
193 +       for ( int i=0; i<m_dOverrides.sphinx_elements(); i++ )
194         {
195                 CSphSEQuery::Override_t * pOverride = m_dOverrides.at(i);
196                 const uint32 uSize = pOverride->m_iType==SPH_ATTR_BIGINT ? 16 : 12; // id64 + value
197 -               iReqSize += strlen ( pOverride->m_sName ) + 12 + uSize*pOverride->m_dIds.elements();
198 +               iReqSize += strlen ( pOverride->m_sName ) + 12 + uSize*pOverride->m_dIds.sphinx_elements();
199         }
200         // select
201         iReqSize += 4;
202 @@ -2012,14 +2064,14 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
203         SendString ( m_sComment );
204  
205         // overrides
206 -       SendInt ( m_dOverrides.elements() );
207 -       for ( int i=0; i<m_dOverrides.elements(); i++ )
208 +       SendInt ( m_dOverrides.sphinx_elements() );
209 +       for ( int i=0; i<m_dOverrides.sphinx_elements(); i++ )
210         {
211                 CSphSEQuery::Override_t * pOverride = m_dOverrides.at(i);
212                 SendString ( pOverride->m_sName );
213                 SendDword ( pOverride->m_iType );
214 -               SendInt ( pOverride->m_dIds.elements() );
215 -               for ( int j=0; j<pOverride->m_dIds.elements(); j++ )
216 +               SendInt ( pOverride->m_dIds.sphinx_elements() );
217 +               for ( int j=0; j<pOverride->m_dIds.sphinx_elements(); j++ )
218                 {
219                         SendUint64 ( pOverride->m_dIds.at(j) );
220                         if ( pOverride->m_iType==SPH_ATTR_FLOAT )
221 @@ -2045,9 +2097,9 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
222  //////////////////////////////////////////////////////////////////////////////
223  // SPHINX HANDLER
224  //////////////////////////////////////////////////////////////////////////////
225 -
226 +#ifndef MARIADB_BASE_VERSION
227  static const char * ha_sphinx_exts[] = { NullS };
228 -
229 +#endif
230  
231  #if MYSQL_VERSION_ID<50100
232  ha_sphinx::ha_sphinx ( TABLE_ARG * table )
233 @@ -2073,8 +2125,10 @@ ha_sphinx::ha_sphinx ( handlerton * hton, TABLE_ARG * table )
234         , m_dUnboundFields ( NULL )
235  {
236         SPH_ENTER_METHOD();
237 +       #if MYSQL_VERSION_ID < 50709
238         if ( current_thd )
239                 current_thd->variables.engine_condition_pushdown = true;
240 +       #endif
241         SPH_VOID_RET();
242  }
243  
244 @@ -2082,11 +2136,24 @@ ha_sphinx::ha_sphinx ( handlerton * hton, TABLE_ARG * table )
245  // If frm_error() is called then we will use this to to find out what file extentions
246  // exist for the storage engine. This is also used by the default rename_table and
247  // delete_table method in handler.cc.
248 +#ifndef MARIADB_BASE_VERSION
249  const char ** ha_sphinx::bas_ext() const
250  {
251         return ha_sphinx_exts;
252  }
253 -
254 +#else
255 +ha_sphinx::~ha_sphinx()
256 +{
257 +  SafeDeleteArray ( m_dAttrs );
258 +  SafeDeleteArray ( m_dUnboundFields );
259 +  if ( m_dFields )
260 +  {
261 +    for (uint32 i=0; i< m_iFields; i++ )
262 +      SafeDeleteArray ( m_dFields[i] );
263 +    delete [] m_dFields;
264 +  }
265 +}
266 +#endif
267  
268  // Used for opening tables. The name will be the name of the file.
269  // A table is opened when it needs to be opened. For instance
270 @@ -2349,11 +2416,19 @@ int ha_sphinx::write_row ( byte * )
271                         sQuery.append ( "''" );
272  
273                 } else
274 -               {
275 +               {       
276 +                       #if  MYSQL_VERSION_ID>=100000
277 +                               THD *thd= ha_thd();
278 +                       #endif
279                         if ( (*ppField)->type()==MYSQL_TYPE_TIMESTAMP )
280                         {
281 -                               Item_field * pWrap = new Item_field ( *ppField ); // autofreed by query arena, I assume
282 -                               Item_func_unix_timestamp * pConv = new Item_func_unix_timestamp ( pWrap );
283 +                               #if  MYSQL_VERSION_ID>=100000
284 +                                       Item_field * pWrap = new (thd->mem_root) Item_field(thd, *ppField); // autofreed by query arena, I assume
285 +                                       Item_func_unix_timestamp * pConv = new (thd->mem_root) Item_func_unix_timestamp(thd, pWrap);
286 +                               #else
287 +                                       Item_field * pWrap = new Item_field ( *ppField ); // autofreed by query arena, I assume
288 +                                       Item_func_unix_timestamp * pConv = new Item_func_unix_timestamp ( pWrap );
289 +                               #endif
290                                 pConv->quick_fix_field();
291                                 unsigned int uTs = (unsigned int) pConv->val_int();
292  
293 @@ -2390,7 +2465,10 @@ int ha_sphinx::write_row ( byte * )
294  
295         unsigned int uTimeout = 1;
296         mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout );
297 -
298 +       #ifdef MARIADB_BASE_VERSION
299 +        my_bool my_true= 1;
300 +        mysql_options(pConn, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, (char*) &my_true);
301 +       #endif
302         if ( !mysql_real_connect ( pConn, m_pShare->m_sHost, "root", "", "", m_pShare->m_iPort, m_pShare->m_sSocket, 0 ) )
303                 SPH_RET ( HandleMysqlError ( pConn, ER_CONNECT_TO_FOREIGN_DATA_SOURCE ) );
304  
305 @@ -2449,6 +2527,10 @@ int ha_sphinx::delete_row ( const byte * )
306  
307         unsigned int uTimeout = 1;
308         mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout );
309 +       #ifdef MARIADB_BASE_VERSION
310 +        my_bool my_true= 1;
311 +        mysql_options(pConn, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, (char*) &my_true);
312 +       #endif
313  
314         if ( !mysql_real_connect ( pConn, m_pShare->m_sHost, "root", "", "", m_pShare->m_iPort, m_pShare->m_sSocket, 0 ) )
315                 SPH_RET ( HandleMysqlError ( pConn, ER_CONNECT_TO_FOREIGN_DATA_SOURCE ) );
316 @@ -2756,11 +2838,19 @@ const Item * ha_sphinx::cond_push ( const Item *cond )
317                                 break;
318  
319                         // copy the query, and let know that we intercepted this condition
320 -                       Item_string * pString = (Item_string *) args[1];
321 -                       pTable->m_bQuery = true;
322 +                       #if MYSQL_VERSION_ID>=100000
323 +                        String *pString= args[1]->val_str(NULL);
324 +                        pTable->m_bQuery = true;
325 +                       strncpy ( pTable->m_sQuery, pString->c_ptr(), sizeof(pTable->m_sQuery) );
326 +                       pTable->m_sQuery[sizeof(pTable->m_sQuery)-1] = '\0';
327 +                       pTable->m_pQueryCharset = pString->charset();
328 +                       #else
329 +                       Item_string * pString = (Item_string *) args[1];
330 +                        pTable->m_bQuery = true;
331                         strncpy ( pTable->m_sQuery, pString->str_value.c_ptr(), sizeof(pTable->m_sQuery) );
332                         pTable->m_sQuery[sizeof(pTable->m_sQuery)-1] = '\0';
333                         pTable->m_pQueryCharset = pString->str_value.charset();
334 +                       #endif
335  
336                 } else
337                 {
338 @@ -3540,7 +3630,7 @@ CSphSEStats * sphinx_get_stats ( THD * thd, SHOW_VAR * out )
339  #endif
340  
341         out->type = SHOW_CHAR;
342 -       out->value = "";
343 +       out->value =  "";
344         return 0;
345  }
346  
347 @@ -3673,7 +3763,25 @@ struct st_mysql_show_var sphinx_status_vars[] =
348         {0, 0, (enum_mysql_show_type)0}
349  };
350  
351 -
352 +#ifdef MARIADB_BASE_VERSION
353 +maria_declare_plugin(sphinx)
354 +{
355 +       MYSQL_STORAGE_ENGINE_PLUGIN,
356 +       &sphinx_storage_engine,
357 +       sphinx_hton_name,
358 +       "Sphinx developers",
359 +       sphinx_hton_comment,
360 +       PLUGIN_LICENSE_GPL,
361 +       sphinx_init_func, // Plugin Init
362 +       sphinx_done_func, // Plugin Deinit
363 +       0x0202, // 2.2
364 +       sphinx_status_vars,
365 +       NULL,
366 +       SPHINXSE_VERSION, // string version
367 +MariaDB_PLUGIN_MATURITY_GAMMA
368 +}
369 +maria_declare_plugin_end;
370 +#else
371  mysql_declare_plugin(sphinx)
372  {
373         MYSQL_STORAGE_ENGINE_PLUGIN,
374 @@ -3690,7 +3798,7 @@ mysql_declare_plugin(sphinx)
375         NULL
376  }
377  mysql_declare_plugin_end;
378 -
379 +#endif
380  #endif // >50100
381  
382  //
383 diff --git a/mysqlse/ha_sphinx.h b/mysqlse/ha_sphinx.h
384 index c44ffca8..897a0e5a 100644
385 --- a/mysqlse/ha_sphinx.h
386 +++ b/mysqlse/ha_sphinx.h
387 @@ -53,14 +53,24 @@ class ha_sphinx : public handler
388  #else
389                                         ha_sphinx ( handlerton * hton, TABLE_ARG * table_arg );
390  #endif
391 -                                       ~ha_sphinx () {}
392 +#ifndef MARIADB_BASE_VERSION
393 +                                       ~ha_sphinx (){}
394 +#else
395 +                                        ~ha_sphinx ();
396 +#endif
397  
398         const char *    table_type () const             { return "SPHINX"; }    ///< SE name for display purposes
399         const char *    index_type ( uint )             { return "HASH"; }              ///< index type name for display purposes
400 -       const char **   bas_ext () const;                                                               ///< my file extensions
401 -
402 +       #ifndef MARIADB_BASE_VERSION
403 +       const char **   bas_ext () const;
404 +       #endif
405         #if MYSQL_VERSION_ID>50100
406 -       ulonglong               table_flags () const    { return HA_CAN_INDEX_BLOBS; }                  ///< bitmap of implemented flags (see handler.h for more info)
407 +       #ifdef MARIADB_BASE_VERSION
408 +       ulonglong               table_flags () const    { return HA_CAN_INDEX_BLOBS | 
409 +                                                                 HA_CAN_TABLE_CONDITION_PUSHDOWN; } ///< bitmap of implemented flags (see handler.h for more info)
410 +       #else
411 +       ulonglong               table_flags () const    { return HA_CAN_INDEX_BLOBS;  }
412 +       #endif
413         #else
414         ulong                   table_flags () const    { return HA_CAN_INDEX_BLOBS; }                  ///< bitmap of implemented flags (see handler.h for more info)
415         #endif
416 @@ -77,8 +87,12 @@ class ha_sphinx : public handler
417         #else
418         virtual double  scan_time ()    { return (double)( records+deleted )/20.0 + 10; }                               ///< called in test_quick_select to determine if indexes should be used
419         #endif
420 -
421 -       virtual double  read_time ( ha_rows rows )      { return (double)rows/20.0 + 1; }                                       ///< index read time estimate
422 +       #ifdef MARIADB_BASE_VERSION
423 +        virtual double read_time(uint index, uint ranges, ha_rows rows)
424 +       { return ranges + (double)rows/20.0 + 1; }                                      ///< index read time estimate
425 +       #else
426 +       virtual double  read_time ( ha_rows rows )      { return (double)rows/20.0 + 1; }
427 +       #endif
428  
429  public:
430         int                             open ( const char * name, int mode, uint test_if_locked );
431 --- storage/sphinx/snippets_udf.cc~     2016-07-19 12:42:18.000000000 +0200
432 +++ storage/sphinx/snippets_udf.cc      2018-03-10 20:16:19.241113584 +0100
433 @@ -34,6 +34,9 @@
434  #include "../mysql_priv.h"
435  #endif
436  
437 +#if  !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID>=50709
438 +       #include <arpa/inet.h>
439 +#endif
440  #include <mysys_err.h>
441  #include <my_sys.h>
442  
This page took 0.111192 seconds and 3 git commands to generate.