-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMysqlIndex.hh
More file actions
81 lines (57 loc) · 2.57 KB
/
MysqlIndex.hh
File metadata and controls
81 lines (57 loc) · 2.57 KB
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
#ifndef MYSQL_INDEX_HH
#define MYSQL_INDEX_HH 1
// $Id$
// MysqlIndex.hh -- Exercise performance of MysqlDB for lookup table.
//
// 20160119 Michael Kelsey
// 20160204 Extend to support blocking data into smaller tables
// 20160216 Add support for doing "bulk updates" from flat files
#include "IndexTester.hh"
#include <mysql/mysql.h> /* Needed for MYSQL typedef below */
#include <string>
#include <vector>
class MysqlIndex : public IndexTester {
public:
MysqlIndex(int verbose=0);
virtual ~MysqlIndex() { cleanup(); }
public:
// Call this function before running to create multiple smaller tables
void setTableSize(objectId_t max=0ULL) { blockSize = max; }
protected:
virtual void create(objectId_t asize);
virtual void update(const char* datafile);
virtual chunkId_t value(objectId_t objID);
virtual void cleanup();
bool connect(const std::string& newDBname="");
void accessDatabase() const;
void createTables() const; // One for all, or multiple
void createTable(int tblidx=-1) const; // >= 0 allows data blocks
void fillTable(int tblidx, objectId_t tsize, objectId_t firstID) const;
void updateTable(const char* datafile, int tblidx=-1) const;
void getObjectRange(int tblidx, objectId_t &minID, objectId_t &maxID) const;
void createLoadFile(const char* datafile, objectId_t fsize,
objectId_t start, unsigned step) const;
void dropTable(int tblidx=-1) const; // Drop specified table
MYSQL_RES* findObjectID(objectId_t objID) const; // Get chunk for given ID
// Wrapper functions to handle multiple tables for data blocks
bool usingMultipleTables() const { // Flag if data is in blocks
return (blockSize != 0ULL && blockSize < tableSize);
}
int numberOfTables() const; // Total number of data blocks
void fillTableRanges(); // Populate ID range lookup
int chooseTable(objectId_t objID) const; // Identify block table for ID
std::string makeTableName(int tblidx=-1) const; // Unique block names
// Wrapper functions to generate and process queries
void sendQuery(const std::string& query) const; // Transmit query to server
void reportError() const; // Print MySQL message if any
MYSQL_RES* getQueryResult() const; // Result container w/err check
chunkId_t extractChunk(MYSQL_RES* result, size_t irow=0) const;
objectId_t extractObject(MYSQL_RES* result, size_t irow=0) const;
protected:
MYSQL *mysqlDB;
std::string dbname;
std::string table;
objectId_t blockSize; // For dividing overly large tables
std::vector<objectId_t> blockStart; // Lowest objectID in each table block
};
#endif /* MYSQL_INDEX_HH */