Merge branch 'master' into optimize

This commit is contained in:
lazio579 2018-12-29 11:18:46 +08:00
commit 1907c7d435
4 changed files with 38 additions and 12 deletions

View File

@ -332,7 +332,7 @@ update后端的state只包括up|down|maintaining三种状态delete/remove后
```
说明
其中配置的IP为特定IP如192.0.0.1目前暂不支持IP段如192.0.0.*)。
其中配置的IP为特定IP如192.0.0.1支持IP段如192.0.0.*)。
```
例如
@ -375,7 +375,7 @@ update后端的state只包括up|down|maintaining三种状态delete/remove后
```
说明
其中配置的IP为特定IP如192.0.0.1暂不支持IP段如192.0.0.*)。
其中配置的IP为特定IP如192.0.0.1支持IP段如192.0.0.*)。
```
例如

View File

@ -386,7 +386,7 @@ XO: 处于XA OVER状态。
```
说明
其中配置的IP为特定IP如192.0.0.1暂不支持IP段如192.0.0.*)。
其中配置的IP为特定IP如192.0.0.1支持IP段如192.0.0.*)。
```
例如
@ -429,7 +429,7 @@ XO: 处于XA OVER状态。
```
说明
其中配置的IP为特定IP如192.0.0.1暂不支持IP段如192.0.0.*)。
其中配置的IP为特定IP如192.0.0.1支持IP段如192.0.0.*)。
```
例如

View File

@ -913,11 +913,11 @@ routing_select(sql_context_t *context, const sql_select_t *select,
stats->com_select_global += 1;
return USE_NON_SHARDING_TABLE;
}
char *db = default_db;
GPtrArray *sharding_tables = g_ptr_array_new();
GList *single_tables = NULL;
int i;
for (i = 0; i < sources->len; ++i) {
char *db = default_db;
sql_src_item_t *src = g_ptr_array_index(sources, i);
char *table = NULL;
if (src->select && sql_select_contains_sharding_table(src->select, &db, &table)) {
@ -933,7 +933,7 @@ routing_select(sql_context_t *context, const sql_select_t *select,
if (src->select) { /* subquery not contain sharding table, try to find single table */
sql_select_get_single_tables(src->select, db, &single_tables);
}
db = src->dbname ? src->dbname : db;
db = src->dbname ? src->dbname : default_db;
if (src->table_name) {
if (shard_conf_is_shard_table(db, src->table_name)) {
g_ptr_array_add(sharding_tables, src);
@ -955,7 +955,7 @@ routing_select(sql_context_t *context, const sql_select_t *select,
GList *l;
for (l = single_tables; l; l = l->next) {
sql_src_item_t *src = l->data;
db = src->dbname ? src->dbname : db;
char *db = src->dbname ? src->dbname : default_db;
shard_conf_get_single_table_distinct_group(groups, db, src->table_name);
}
if (groups->len > 1) {
@ -975,7 +975,7 @@ routing_select(sql_context_t *context, const sql_select_t *select,
sql_expr_find_subqueries(select->where_clause, &subqueries);
GList *l;
for (l = subqueries; l; l = l->next) {
if (sql_select_has_single_table(l->data, db)) {
if (sql_select_has_single_table(l->data, default_db)) {
g_ptr_array_free(sharding_tables, TRUE);
g_list_free(subqueries);
sql_context_append_msg(context, "(cetus) Found single-table in subquery, not allowed");
@ -992,7 +992,7 @@ routing_select(sql_context_t *context, const sql_select_t *select,
}
if (sharding_tables->len >= 2) {
if (!join_on_sharding_key(db, sharding_tables, select->where_clause)) {
if (!join_on_sharding_key(default_db, sharding_tables, select->where_clause)) {
g_ptr_array_free(sharding_tables, TRUE);
sql_context_append_msg(context, "(proxy)JOIN must inside VDB and have explicit join-on condition");
return ERROR_UNPARSABLE;
@ -1002,7 +1002,7 @@ routing_select(sql_context_t *context, const sql_select_t *select,
gboolean has_sharding_key = FALSE;
for (i = 0; i < sharding_tables->len; ++i) {
sql_src_item_t *shard_table = g_ptr_array_index(sharding_tables, i);
db = shard_table->dbname ? shard_table->dbname : db;
char *db = shard_table->dbname ? shard_table->dbname : default_db;
sharding_table_t *shard_info = shard_conf_get_info(db, shard_table->table_name);
@ -1017,7 +1017,7 @@ routing_select(sql_context_t *context, const sql_select_t *select,
GPtrArray *partitions = g_ptr_array_new(); /* GPtrArray<sharding_partition_t *> */
for (i = 0; i < sharding_tables->len; ++i) {
sql_src_item_t *shard_table = g_ptr_array_index(sharding_tables, 0);
db = shard_table->dbname ? shard_table->dbname : db;
char *db = shard_table->dbname ? shard_table->dbname : default_db;
shard_conf_table_partitions(partitions, db, shard_table->table_name);
int rc = partitions_filter_expr(partitions, select->where_clause);
@ -1047,7 +1047,7 @@ routing_select(sql_context_t *context, const sql_select_t *select,
OR sharding key filter out all groups */
for (i = 0; i < sharding_tables->len; ++i) {
sql_src_item_t *shard_table = g_ptr_array_index(sharding_tables, 0);
db = shard_table->dbname ? shard_table->dbname : db;
char *db = shard_table->dbname ? shard_table->dbname : default_db;
shard_conf_get_table_groups(groups, db, shard_table->table_name);
}
g_ptr_array_free(sharding_tables, TRUE);

View File

@ -339,6 +339,19 @@ assign_default_username(const gchar *newval, gpointer param) {
g_free(srv->default_username);
}
srv->default_username = g_strdup(newval);
network_backends_t *bs = srv->priv->backends;
gint count = network_backends_count(bs);
gint i = 0;
for (i = 0; i < count; i++) {
network_backend_t *backend = network_backends_get(bs, i);
if (backend) {
if (backend->config->default_username) {
g_string_free(backend->config->default_username, TRUE);
}
backend->config->default_username = g_string_new(NULL);
g_string_append(backend->config->default_username, srv->default_username);
}
}
ret = ASSIGN_OK;
} else {
ret = ASSIGN_VALUE_INVALID;
@ -375,6 +388,19 @@ assign_default_db(const gchar *newval, gpointer param) {
g_free(srv->default_db);
}
srv->default_db = g_strdup(newval);
network_backends_t *bs = srv->priv->backends;
gint count = network_backends_count(bs);
gint i = 0;
for (i = 0; i < count; i++) {
network_backend_t *backend = network_backends_get(bs, i);
if (backend) {
if (backend->config->default_db) {
g_string_free(backend->config->default_db, TRUE);
}
backend->config->default_db = g_string_new(NULL);
g_string_append(backend->config->default_db, srv->default_db);
}
}
ret = ASSIGN_OK;
} else {
ret = ASSIGN_VALUE_INVALID;