File: ha_sphinx.h

package info (click to toggle)
mariadb 1%3A11.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 765,428 kB
  • sloc: ansic: 2,382,827; cpp: 1,803,532; asm: 378,315; perl: 63,176; sh: 46,496; pascal: 40,776; java: 39,363; yacc: 20,428; python: 19,506; sql: 17,864; xml: 12,463; ruby: 8,544; makefile: 6,059; cs: 5,855; ada: 1,700; lex: 1,193; javascript: 1,039; objc: 80; tcl: 73; awk: 46; php: 22
file content (178 lines) | stat: -rw-r--r-- 5,729 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//
// $Id: ha_sphinx.h 4818 2014-09-24 08:53:38Z tomat $
//

#if MYSQL_VERSION_ID>=50515
#define TABLE_ARG	TABLE_SHARE
#elif MYSQL_VERSION_ID>50100
#define TABLE_ARG	st_table_share
#else
#define TABLE_ARG	st_table
#endif


#if MYSQL_VERSION_ID>=50120
typedef uchar byte;
#endif


/// forward decls
class THD;
struct CSphReqQuery;
struct CSphSEShare;
struct CSphSEAttr;
struct CSphSEStats;
struct CSphSEThreadTable;

/// Sphinx SE handler class
class ha_sphinx final : public handler
{
protected:
	THR_LOCK_DATA	m_tLock;				///< MySQL lock

	CSphSEShare *	m_pShare;				///< shared lock info

	uint			m_iMatchesTotal;
	uint			m_iCurrentPos;
	const byte *	m_pCurrentKey;
	uint			m_iCurrentKeyLen;

	char *			m_pResponse;			///< searchd response storage
	char *			m_pResponseEnd;			///< searchd response storage end (points to wilderness!)
	char *			m_pCur;					///< current position into response
	bool			m_bUnpackError;			///< any errors while unpacking response

public:
#if MYSQL_VERSION_ID<50100
					ha_sphinx ( TABLE_ARG * table_arg ); // NOLINT
#else
					ha_sphinx ( handlerton * hton, TABLE_ARG * table_arg );
#endif
					~ha_sphinx ();

	const char *	table_type () const override		{ return "SPHINX"; }	///< SE name for display purposes
	const char *	index_type ( uint ) override		{ return "HASH"; }		///< index type name for display purposes

	#if MYSQL_VERSION_ID>50100
	ulonglong		table_flags () const override	{ return HA_CAN_INDEX_BLOBS | 
                                                                 HA_CAN_TABLE_CONDITION_PUSHDOWN; } ///< bitmap of implemented flags (see handler.h for more info)
	#else
	ulong			table_flags () const	{ return HA_CAN_INDEX_BLOBS; }			///< bitmap of implemented flags (see handler.h for more info)
	#endif

	ulong			index_flags ( uint, uint, bool ) const override	{ return 0; }	///< bitmap of flags that says how SE implements indexes
	uint			max_supported_record_length () const override	{ return HA_MAX_REC_LENGTH; }
	uint			max_supported_keys () const override				{ return 1; }
	uint			max_supported_key_parts () const override		{ return 1; }
	uint			max_supported_key_length () const override		{ return MAX_KEY_LENGTH; }
	uint			max_supported_key_part_length () const override	{ return MAX_KEY_LENGTH; }

	IO_AND_CPU_COST	scan_time () override
	{
          IO_AND_CPU_COST cost;
          cost.io= 0;
          cost.cpu= (double) (stats.records+stats.deleted) * DISK_READ_COST;
          return cost;
        }
        IO_AND_CPU_COST keyread_time(uint index, ulong ranges, ha_rows rows,
                                    ulonglong blocks) override
	{
          IO_AND_CPU_COST cost;
          cost.io= ranges;
          cost.cpu= 0;
          return cost;
        }
        IO_AND_CPU_COST rnd_pos_time(ha_rows rows) override
	{
          IO_AND_CPU_COST cost;
          cost.io= 0;
          cost.cpu= 0;
          return cost;
        }

public:
	int				open ( const char * name, int mode, uint test_if_locked ) override;
	int				close () override;

	int				write_row ( const byte * buf ) override;
	int				update_row ( const byte * old_data, const byte * new_data ) override;
	int				delete_row ( const byte * buf ) override;
	int				extra ( enum ha_extra_function op ) override;

	int				index_init ( uint keynr, bool sorted ) override; // 5.1.x
	int				index_init ( uint keynr ) { return index_init ( keynr, false ); } // 5.0.x

	int				index_end () override;
	int				index_read ( byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag ) override;
	int				index_read_idx ( byte * buf, uint idx, const byte * key, uint key_len, enum ha_rkey_function find_flag );
	int				index_next ( byte * buf ) override;
	int				index_next_same ( byte * buf, const byte * key, uint keylen ) override;
	int				index_prev ( byte * buf ) override;
	int				index_first ( byte * buf ) override;
	int				index_last ( byte * buf ) override;

	int				get_rec ( byte * buf, const byte * key, uint keylen );

	int				rnd_init ( bool scan ) override;
	int				rnd_end () override;
	int				rnd_next ( byte * buf ) override;
	int				rnd_pos ( byte * buf, byte * pos ) override;
	void			position ( const byte * record ) override;

#if MYSQL_VERSION_ID>=50030
	int				info ( uint ) override;
#else
	void			info ( uint );
#endif

	int				reset() override;
	int				external_lock ( THD * thd, int lock_type ) override;
	int				delete_all_rows () override;
	ha_rows			        records_in_range ( uint inx, const key_range * min_key, const key_range * max_key,  page_range *pages) override;

	int				delete_table ( const char * from ) override;
	int				rename_table ( const char * from, const char * to ) override;
	int				create ( const char * name, TABLE * form, HA_CREATE_INFO * create_info ) override;

	THR_LOCK_DATA **		store_lock ( THD * thd, THR_LOCK_DATA ** to, enum thr_lock_type lock_type ) override;

public:
#if MYSQL_VERSION_ID<50610
	virtual const COND *	cond_push ( const COND *cond );
#else
	const Item *		cond_push ( const Item *cond ) override;
#endif	
	void			cond_pop () override;

private:
	uint32			m_iFields;
	char **			m_dFields;

	uint32			m_iAttrs;
	CSphSEAttr *	m_dAttrs;
	int				m_bId64;

	int *			m_dUnboundFields;

private:
	int				Connect ( const char * sQueryHost, ushort uPort );
	int				ConnectAPI ( const char * sQueryHost, int iQueryPort );
	int				HandleMysqlError ( struct st_mysql * pConn, int iErrCode );

	uint32			UnpackDword ();
	char *			UnpackString ();
	bool			UnpackSchema ();
	bool			UnpackStats ( CSphSEStats * pStats );
	bool			CheckResponcePtr ( int iLen );

	CSphSEThreadTable *	GetTls ();
};


#if MYSQL_VERSION_ID < 50100
bool sphinx_show_status ( THD * thd );
#endif

//
// $Id: ha_sphinx.h 4818 2014-09-24 08:53:38Z tomat $
//