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