MXS-1310: Detect implicit database usage
When the current database is implicitly used in a query that also uses an explicit database, it must be routed to the shard which has the current database. As cross-shard joins are not supported, the safest, and possibly the most expected course of action to take, is to route it to the so-called default shard. The default shard is the shard that contains the database that is currently set as the active database with a COM_INIT_DB, a text protocol USE <database> query or it was set at connection time.
This commit is contained in:
parent
5ed6483f01
commit
0c33572a96
@ -459,11 +459,30 @@ char* get_shard_target_name(ROUTER_INSTANCE* router,
|
||||
char** dbnms = NULL;
|
||||
char* rval = NULL, *query, *tmp = NULL;
|
||||
bool has_dbs = false; /**If the query targets any database other than the current one*/
|
||||
bool uses_implicit_databases = false;
|
||||
|
||||
dbnms = qc_get_database_names(buffer, &sz);
|
||||
dbnms = qc_get_table_names(buffer, &sz, true);
|
||||
|
||||
for (i = 0; i < sz; i++)
|
||||
{
|
||||
if (strchr(dbnms[i], '.') == NULL)
|
||||
{
|
||||
uses_implicit_databases = true;
|
||||
}
|
||||
MXS_FREE(dbnms[i]);
|
||||
}
|
||||
MXS_FREE(dbnms);
|
||||
|
||||
HASHTABLE* ht = client->shardmap->hash;
|
||||
|
||||
if (uses_implicit_databases)
|
||||
{
|
||||
MXS_INFO("Query implicitly uses the current database");
|
||||
return (char*)hashtable_fetch(ht, client->current_db);
|
||||
}
|
||||
|
||||
dbnms = qc_get_database_names(buffer, &sz);
|
||||
|
||||
if (sz > 0)
|
||||
{
|
||||
for (i = 0; i < sz; i++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user