Partial whitespace cleanup.

Conflicts:
	storage/oqgraph/ha_oqgraph.cc

Conflicts:
	storage/oqgraph/ha_oqgraph.cc
This commit is contained in:
Andrew McDonnell 2014-10-25 20:00:41 +10:30
parent 826141368c
commit abf1e259f6

View file

@ -24,12 +24,12 @@
*/
#ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation // gcc: Class implementation
#pragma implementation // gcc: Class implementation
#endif
#include <my_config.h>
#define MYSQL_SERVER 1 // to have THD
#define MYSQL_SERVER // to have THD
#include <mysql/plugin.h>
#include "sql_class.h"
@ -41,12 +41,12 @@
#include "graphcore.h"
#include <sql_error.h>
#if MYSQL_VERSION_ID >= 100004
#if MYSQL_VERSION_ID >= 100004
// Interim workaround for rename in sql_error.h from this point
#define MYSQL_ERROR Sql_condition
#endif
#if MYSQL_VERSION_ID < 100000
#if MYSQL_VERSION_ID < 100000
// Allow compatibility with build for 5.5.32
#define user_defined_key_parts key_parts
#define open_table_error(a,b,c) open_table_error(a,b,c,0)
@ -84,8 +84,8 @@ using namespace open_query;
#ifdef RETAIN_INT_LATCH_COMPATIBILITY
/* In normal operation, no new tables using an integer latch can be created,
* but they can still be used if they already exist, to allow for upgrades.
*
* However to ensure the legacy function is properly tested, we add a
*
* However to ensure the legacy function is properly tested, we add a
* server variable "oggraph_allow_create_integer_latch" which if set to TRUE
* allows new engine tables to be created with integer latches.
*/
@ -103,8 +103,8 @@ struct oqgraph_latch_op_table { const char *key; int latch; };
static const oqgraph_latch_op_table latch_ops_table[] = {
{ "", oqgraph::NO_SEARCH } , // suggested by Arjen, use empty string instead of no_search
{ "dijkstras", oqgraph::DIJKSTRAS } ,
{ "breadth_first", oqgraph::BREADTH_FIRST } ,
{ NULL, -1 }
{ "breadth_first", oqgraph::BREADTH_FIRST } ,
{ NULL, -1 }
};
static uint32 findLongestLatch() {
@ -216,9 +216,9 @@ static bool oqgraph_init()
hton->flags= HTON_ALTER_NOT_SUPPORTED;
// Prevent ALTER, because the core crashes when the user provides a
// non-existing backing store field for ORIGID, etc
// 'Fixes' bug 1134355
// 'Fixes' bug 1134355
// HTON_NO_FLAGS;
hton->table_options= (ha_create_table_option*)oqgraph_table_option_list;
oqgraph_init_done= TRUE;
return 0;
@ -268,10 +268,10 @@ static int error_code(int res)
* linkid BIGINT UNSIGNED NULL
* =================================
*
The latch may be a varchar of any length, however if it is too short to
hold the longest latch value, table creation is aborted.
CREATE TABLE foo (
latch VARCHAR(32) NULL,
origid BIGINT UNSIGNED NULL,
@ -293,12 +293,12 @@ static int error_code(int res)
integer and change behaviour accordingly.
Note that if a table was constructed with varchar and an attempt is made to
select with latch=(some integer number) then MYSQL will autocast
and no data will be returned... so retaining compatibility does not and cannot
and no data will be returned... so retaining compatibility does not and cannot
extend to making old queries work with new style tables.
This method is only called on table creation, so here we ensure new tables
can only be created with varchar.
This does present a small problem with regression testing;
so we work around that by using an system variable to allow
integer latch tables to be created.
@ -336,11 +336,11 @@ int ha_oqgraph::oqgraph_check_table_structure (TABLE *table_arg)
DBUG_PRINT( "oq-debug", ("Allowing integer latch anyway!"));
isStringLatch = false;
/* Make a warning */
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX),
"latch SMALLINT UNSIGNED NULL", "'latch VARCHAR(32) NULL'");
} else
#endif
#endif
if (isLatchColumn && ((*field)->type() == MYSQL_TYPE_SHORT))
{
DBUG_PRINT( "oq-debug", ("Allowing integer no more!"));
@ -352,7 +352,7 @@ int ha_oqgraph::oqgraph_check_table_structure (TABLE *table_arg)
badColumn = true;
push_warning_printf( current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Column %d is wrong type.", i);
}
// Make sure latch column is large enough for all possible latch values
if (isLatchColumn && isStringLatch) {
if ((*field)->char_length() < findLongestLatch()) {
@ -498,7 +498,7 @@ void ha_oqgraph::fprint_error(const char* fmt, ...)
*
* An OQGRAPH table is effectively similar to a view over the underlying backing table,
* attribute 'data_table', but where the result returned by a query depends on the
* value of the 'latch' column specified to the query. Therefore,
* value of the 'latch' column specified to the query. Therefore,
* when mysqld opens us, we need to open the corresponding backing table 'data_table'
*
*/
@ -553,7 +553,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
// * plen seems to be then set to length of `database_blah/options_data_table_name`
// * then we set share->normalized_path.str and share->path.str to `database_blah/options_data_table_name`
// * I assume that this verbiage is needed so the memory used by share->path.str is set in the share mem root
// * because otherwise one could simply build the string more simply using malloc and pass it instead of "" above
// * because otherwise one could simply build the string more simply using malloc and pass it instead of "" above
const char* p= strend(name)-1;
while (p > name && *p != '\\' && *p != '/')
--p;
@ -568,11 +568,11 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
share->normalized_path.str= share->path.str;
share->path.length= share->normalized_path.length= plen;
DBUG_PRINT( "oq-debug", ("share:(normalized_path=%s,path.length=%zu)",
DBUG_PRINT( "oq-debug", ("share:(normalized_path=%s,path.length=%zu)",
share->normalized_path.str, share->path.length));
int open_def_flags = 0;
#if MYSQL_VERSION_ID >= 100002
#if MYSQL_VERSION_ID>= 100002
open_def_flags = GTS_TABLE;
#endif
// We want to open the definition for the given backing table
@ -584,7 +584,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
// Lets try without this, and see if all the tests pass...
while (open_table_def(thd, share, open_def_flags))
{
#if MYSQL_VERSION_ID < 100002
#if MYSQL_VERSION_ID < 100002
if (thd->is_error() && thd->stmt_da->sql_errno() != ER_NO_SUCH_TABLE)
{
free_table_share(share);
@ -602,7 +602,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
#else
open_table_error(share, OPEN_FRM_OPEN_ERROR, ENOENT);
free_table_share(share);
if (thd->is_error())
if (thd->is_error())
DBUG_RETURN(thd->get_stmt_da()->sql_errno());
DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
#endif
@ -703,7 +703,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
free_table_share(share);
DBUG_RETURN(-1);
}
// Make sure origid column != destid column
if (strcmp( origid->field_name, destid->field_name)==0) {
fprint_error("Invalid OQGRAPH backing store ('%s.destid' attribute set to same column as origid attribute)", p+1, options->table_name);
@ -809,8 +809,7 @@ int ha_oqgraph::delete_row(const byte * buf)
return HA_ERR_TABLE_READONLY;
}
int ha_oqgraph::index_read(byte * buf, const byte * key, uint key_len,
enum ha_rkey_function find_flag)
int ha_oqgraph::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag)
{
DBUG_ASSERT(inited==INDEX);
// reset before we have a cursor, so the memory is not junk, avoiding the sefgault in position() when select with order by (bug #1133093)
@ -833,7 +832,7 @@ int ha_oqgraph::index_next_same(byte *buf, const byte *key, uint key_len)
#define LATCH_WAS_NUMBER 1
/**
* This function parse the VARCHAR(n) latch specification into an integer operation specification compatible with
* This function parse the VARCHAR(n) latch specification into an integer operation specification compatible with
* v1-v3 oqgraph::search().
*
* If the string contains a number, this is directly converted from a decimal integer.
@ -844,19 +843,19 @@ int ha_oqgraph::index_next_same(byte *buf, const byte *key, uint key_len)
*
* FIXME: For the time being, only handles latin1 character set.
* @return false if parsing fails.
*/
*/
static int parse_latch_string_to_legacy_int(const String& value, int &latch)
{
// Attempt to parse as exactly an integer first.
// Note: we are strict about not having whitespace, or garbage characters,
// so that the query result gets returned properly:
// so that the query result gets returned properly:
// Because of the way the result is built and used in fill_result,
// we have to exactly return in the latch column what was in the latch= clause
// otherwise the rows get filtered out by the query optimiser.
// For the same reason, we cant simply treat latch='' as NO_SEARCH either.
String latchValue = value;
char *eptr;
unsigned long int v = strtoul( latchValue.c_ptr_safe(), &eptr, 10);
@ -866,7 +865,7 @@ static int parse_latch_string_to_legacy_int(const String& value, int &latch)
latch = v;
return true;
}
// fall through and test as a string (although it is unlikely we might have an operator starting with a number)
// fall through and test as a string (although it is unlikely we might have an operator starting with a number)
}
const oqgraph_latch_op_table* entry = latch_ops_table;
@ -880,7 +879,7 @@ static int parse_latch_string_to_legacy_int(const String& value, int &latch)
}
int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
uint key_len, enum ha_rkey_function find_flag)
{
Field **field= table->field;
KEY *key_info= table->key_info + index;
@ -910,7 +909,7 @@ int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key,
#ifdef RETAIN_INT_LATCH_COMPATIBILITY
if (field[0]->type() == MYSQL_TYPE_SHORT) {
latch= (int) field[0]->val_int();
} else
} else
#endif
{
field[0]->val_str(&latchFieldValue, &latchFieldValue);
@ -918,13 +917,13 @@ int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key,
// Invalid, so warn & fail
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_WRONG_ARGUMENTS, ER(ER_WRONG_ARGUMENTS), "OQGRAPH latch");
table->status = STATUS_NOT_FOUND;
if (ptrdiff) /* fixes debug build assert - should be a tidier way to do this */
{
field[0]->move_field_offset(-ptrdiff);
field[1]->move_field_offset(-ptrdiff);
field[2]->move_field_offset(-ptrdiff);
}
dbug_tmp_restore_column_map(table->read_set, old_map);
if (ptrdiff) /* fixes debug build assert - should be a tidier way to do this */
{
field[0]->move_field_offset(-ptrdiff);
field[1]->move_field_offset(-ptrdiff);
field[2]->move_field_offset(-ptrdiff);
}
dbug_tmp_restore_column_map(table->read_set, old_map);
return error_code(oqgraph::NO_MORE_DATA);
}
}
@ -961,11 +960,11 @@ int ha_oqgraph::index_read_idx(byte * buf, uint index, const byte * key,
graph->retainLatchFieldValue(latchFieldValue.c_ptr_safe());
else
graph->retainLatchFieldValue(NULL);
DBUG_PRINT( "oq-debug", ("index_read_idx ::>> search(latch:%s,%ld,%ld)",
DBUG_PRINT( "oq-debug", ("index_read_idx ::>> search(latch:%s,%ld,%ld)",
oqlatchToCode(latch), orig_idp?(long)*orig_idp:-1, dest_idp?(long)*dest_idp:-1));
res= graph->search(latchp, orig_idp, dest_idp);
DBUG_PRINT( "oq-debug", ("search() = %d", res));
@ -996,7 +995,7 @@ int ha_oqgraph::fill_record(byte *record, const open_query::row &row)
field[5]->move_field_offset(ptrdiff);
}
DBUG_PRINT( "oq-debug", ("fill_record() ::>> %s,%ld,%ld,%lf,%ld,%ld",
DBUG_PRINT( "oq-debug", ("fill_record() ::>> %s,%ld,%ld,%lf,%ld,%ld",
row.latch_indicator ? oqlatchToCode((int)row.latch) : "-",
row.orig_indicator ? (long)row.orig : -1,
row.dest_indicator ? (long)row.dest : -1,
@ -1014,10 +1013,10 @@ int ha_oqgraph::fill_record(byte *record, const open_query::row &row)
}
#ifdef RETAIN_INT_LATCH_COMPATIBILITY
else if (field[0]->type() == MYSQL_TYPE_SHORT) {
field[0]->store((longlong) row.latch, 0);
field[0]->store((longlong) row.latch, 0);
}
#endif
}
if (row.orig_indicator)
@ -1094,7 +1093,7 @@ int ha_oqgraph::rnd_pos(byte * buf, byte *pos)
void ha_oqgraph::position(const byte *record)
{
graph->row_ref((void*) ref); // Ref is aligned
graph->row_ref((void*) ref); // Ref is aligned
}
int ha_oqgraph::cmp_ref(const byte *ref1, const byte *ref2)
@ -1141,9 +1140,7 @@ int ha_oqgraph::external_lock(THD *thd, int lock_type)
}
THR_LOCK_DATA **ha_oqgraph::store_lock(THD *thd,
THR_LOCK_DATA **to,
enum thr_lock_type lock_type)
THR_LOCK_DATA **ha_oqgraph::store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type)
{
return edges->file->store_lock(thd, to, lock_type);
}
@ -1168,10 +1165,10 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
key_range *max_key)
{
KEY *key=table->key_info+inx;
#ifdef VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
{
String temp;
key->key_part[0].field->val_str(&temp);
key->key_part[0].field->val_str(&temp);
temp.c_ptr_safe();
DBUG_PRINT( "oq-debug", ("records_in_range ::>> inx=%u", inx));
DBUG_PRINT( "oq-debug", ("records_in_range ::>> key0=%s.", temp.c_ptr())); // for some reason when I had ...inx=%u key=%s", inx, temp.c_ptr_safe()) it printed nothing ...
@ -1186,28 +1183,28 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
{
if (min_key->length == key->key_part[0].store_length && !key->key_part[0].field->is_null()) /* ensure select * from x where latch is null is consistent with no latch */
{
// If latch is not null and equals 0, return # nodes
// If latch is not null and equals 0, return # nodes
// How to decode the key, For VARCHAR(32), from empirical observation using the debugger
// and information gleaned from:
// http://grokbase.com/t/mysql/internals/095h6ch1q7/parsing-key-information
// http://dev.mysql.com/doc/internals/en/support-for-indexing.html#parsing-key-information
// comments in opt_range.cc
// POSSIBLY ONLY VALID FOR INNODB!
// For a the following query:
// SELECT * FROM graph2 WHERE latch = 'breadth_first' AND origid = 123 AND weight = 1;
// key->key_part[0].field->ptr is the value of latch, which is a 1-byte string length followed by the value ('breadth_first')
// key->key_part[2].field->ptr is the value of origid (123)
// key->key_part[1].field->ptr is the value of destid which is not specified in the query so we ignore it in this case
// so given this ordering we seem to be using the second key specified in create table (aka KEY (latch, destid, origid) USING HASH ))
// min_key->key[0] is the 'null' bit and contains 0 in this instance
// min_key->key[1..2] seems to be 16-bit string length
// min_key->key[3..34] hold the varchar(32) value which is that specified in the query
// min_key->key[35] is the null bit of origid
// min_key->key[36..43] is the value in the query (123)
// max_key->key[0] is the ;null' bit and contains 0 in this instance
// max_key->key[1..2] seems to be 16-bit string length
// max_key->key[3..34] hold the varchar(32) value which is that specified in the query
@ -1215,9 +1212,9 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
// max_key->key[36..43] is the value in the query (123)
// But after knowing all that, all we care about is the latch value
// First draft - ignore most of the stuff, but will likely break if query altered
// It turns out there is a better way though, to access the string,
// as demonstrated in key_unpack() of sql/key.cc
String latchCode;
@ -1225,12 +1222,12 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
if (key->key_part[0].field->type() == MYSQL_TYPE_VARCHAR) {
key->key_part[0].field->val_str(&latchCode);
parse_latch_string_to_legacy_int( latchCode, latch);
}
// what if someone did something dumb, like mismatching the latches?
#ifdef RETAIN_INT_LATCH_COMPATIBILITY
else if (key->key_part[0].field->type() == MYSQL_TYPE_SHORT) {
// If not null, and zero ...
@ -1243,17 +1240,17 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
latch = oqgraph::NO_SEARCH;
}
}
#endif
#endif
if (latch != oqgraph::NO_SEARCH) {
// Invalid key type...
// Invalid key type...
// Don't assert, in case the user used alter table on us
return HA_POS_ERROR; // Can only use exact keys
return HA_POS_ERROR; // Can only use exact keys
}
unsigned N = graph->vertices_count();
DBUG_PRINT( "oq-debug", ("records_in_range ::>> N=%u (vertices)", N));
return N;
}
return HA_POS_ERROR; // Can only use exact keys
return HA_POS_ERROR; // Can only use exact keys
}
if (stats.records <= 1) {
@ -1271,13 +1268,12 @@ ha_rows ha_oqgraph::records_in_range(uint inx, key_range *min_key,
}
int ha_oqgraph::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info)
int ha_oqgraph::create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info)
{
oqgraph_table_option_struct *options=
reinterpret_cast<oqgraph_table_option_struct*>(table_arg->s->option_struct);
DBUG_ENTER("ha_oqgraph::create");
DBUG_ENTER("ha_oqgraph::create");
DBUG_PRINT( "oq-debug", ("create(name=%s)", name));
if (oqgraph_check_table_structure(table_arg)) {
@ -1330,7 +1326,7 @@ maria_declare_plugin(oqgraph)
oqgraph_sysvars, /* system variables */
#else
NULL,
#endif
#endif
"3.0",
MariaDB_PLUGIN_MATURITY_BETA
}