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
5 #include "../mysql_priv.h"
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
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>
23 +#define sphinx_append append
24 +#define sphinx_array Dynamic_array
25 +#define sphinx_elements elements
28 #include <mysys_err.h>
30 #include <mysql.h> // include client for INSERT table (sort of redoing federated..)
35 + #if !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID>=50709
36 + #include <arpa/inet.h>
44 #define SafeDelete(_arg) { if ( _arg ) delete ( _arg ); (_arg) = NULL; }
45 #define SafeDeleteArray(_arg) { if ( _arg ) delete [] ( _arg ); (_arg) = NULL; }
47 +#if !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID>=50709
49 +typedef native_mutex_t pthread_mutex_t;
53 //////////////////////////////////////////////////////////////////////////////
55 /// per-table structure that will be shared among all open Sphinx SE handlers
58 char * m_sName; ///< points to query buffer
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;
65 - Dynamic_array<Override_t *> m_dOverrides;
66 + sphinx_array<Override_t *> m_dOverrides;
69 char m_sParseError[256];
71 void SendString ( const char * v ) { int iLen = strlen(v); SendDword(iLen); SendBytes ( v, iLen ); }
72 void SendFloat ( float v ) { SendDword ( sphF2DW(v) ); }
75 +#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
76 template int CSphSEQuery::ParseArray<uint32> ( uint32 **, const char * );
77 template int CSphSEQuery::ParseArray<longlong> ( longlong **, const char * );
80 //////////////////////////////////////////////////////////////////////////////
82 #if MYSQL_VERSION_ID>50100
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 );
91 sphinx_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0,
92 sphinx_get_key, 0, 0 );
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;
101 + hton->db_type = DB_TYPE_AUTOASSIGN;
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 @@
109 CSphTLS * pTls = (CSphTLS*) thd->ha_data[sphinx_hton.slot];
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 ) );
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 ) );
120 if ( protocol->send_fields ( &field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF ) )
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) );
132 @@ -1412,6 +1455,15 @@
136 +static bool myisjson ( char c )
146 bool CSphSEQuery::ParseField ( char * sField )
148 @@ -1623,7 +1675,7 @@
151 tFilter.m_sAttrName = sValue;
152 - while ( (*sValue) && ( myisattr(*sValue) || myismagic(*sValue) ) )
153 + while ( (*sValue) && ( myisattr(*sValue) || myismagic(*sValue) ) || myisjson(*sValue) )
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 );
165 ulonglong uId = strtoull ( sId, NULL, 10 );
166 @@ -1801,8 +1853,8 @@
168 tValue.m_uValue = (uint32)strtoul ( sValue, NULL, 10 );
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 );
177 @@ -1906,11 +1958,11 @@
178 iReqSize += 8 + strlen(m_sFieldWeight[i] );
181 - for ( int i=0; i<m_dOverrides.elements(); i++ )
182 + for ( int i=0; i<m_dOverrides.sphinx_elements(); i++ )
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();
191 @@ -2012,14 +2064,14 @@
192 SendString ( m_sComment );
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++ )
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++ )
208 SendUint64 ( pOverride->m_dIds.at(j) );
209 if ( pOverride->m_iType==SPH_ATTR_FLOAT )
210 @@ -2045,9 +2097,9 @@
211 //////////////////////////////////////////////////////////////////////////////
213 //////////////////////////////////////////////////////////////////////////////
215 +#ifndef MARIADB_BASE_VERSION
216 static const char * ha_sphinx_exts[] = { NullS };
220 #if MYSQL_VERSION_ID<50100
221 ha_sphinx::ha_sphinx ( TABLE_ARG * table )
222 @@ -2073,8 +2125,10 @@
223 , m_dUnboundFields ( NULL )
226 + #if MYSQL_VERSION_ID < 50709
228 current_thd->variables.engine_condition_pushdown = true;
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
240 return ha_sphinx_exts;
244 +ha_sphinx::~ha_sphinx()
246 + SafeDeleteArray ( m_dAttrs );
247 + SafeDeleteArray ( m_dUnboundFields );
250 + for (uint32 i=0; i< m_iFields; i++ )
251 + SafeDeleteArray ( m_dFields[i] );
252 + delete [] m_dFields;
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 ( "''" );
265 + #if MYSQL_VERSION_ID>=100000
266 + THD *thd= ha_thd();
268 if ( (*ppField)->type()==MYSQL_TYPE_TIMESTAMP )
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);
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 );
279 pConv->quick_fix_field();
280 unsigned int uTs = (unsigned int) pConv->val_int();
282 @@ -2390,7 +2465,10 @@
284 unsigned int uTimeout = 1;
285 mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout );
287 + #ifdef MARIADB_BASE_VERSION
288 + my_bool my_true= 1;
289 + mysql_options(pConn, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, (char*) &my_true);
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 ) );
294 @@ -2449,6 +2527,10 @@
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);
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 @@
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();
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();
327 @@ -3540,7 +3630,7 @@
330 out->type = SHOW_CHAR;
336 @@ -3673,7 +3763,25 @@
337 {0, 0, (enum_mysql_show_type)0}
341 +#ifdef MARIADB_BASE_VERSION
342 +maria_declare_plugin(sphinx)
344 + MYSQL_STORAGE_ENGINE_PLUGIN,
345 + &sphinx_storage_engine,
347 + "Sphinx developers",
348 + sphinx_hton_comment,
349 + PLUGIN_LICENSE_GPL,
350 + sphinx_init_func, // Plugin Init
351 + sphinx_done_func, // Plugin Deinit
353 + sphinx_status_vars,
355 + SPHINXSE_VERSION, // string version
356 +MariaDB_PLUGIN_MATURITY_GAMMA
358 +maria_declare_plugin_end;
360 mysql_declare_plugin(sphinx)
362 MYSQL_STORAGE_ENGINE_PLUGIN,
363 @@ -3690,7 +3798,7 @@
366 mysql_declare_plugin_end;
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
377 ha_sphinx ( handlerton * hton, TABLE_ARG * table_arg );
380 +#ifndef MARIADB_BASE_VERSION
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
390 + #ifndef MARIADB_BASE_VERSION
391 + const char ** bas_ext () const;
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)
399 + ulonglong table_flags () const { return HA_CAN_INDEX_BLOBS; }
402 ulong table_flags () const { return HA_CAN_INDEX_BLOBS; } ///< bitmap of implemented flags (see handler.h for more info)
406 virtual double scan_time () { return (double)( records+deleted )/20.0 + 10; } ///< called in test_quick_select to determine if indexes should be used
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
414 + virtual double read_time ( ha_rows rows ) { return (double)rows/20.0 + 1; }
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
423 #include "../mysql_priv.h"
426 +#if !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID>=50709
427 + #include <arpa/inet.h>
429 #include <mysys_err.h>