Skip to content
Snippets Groups Projects
Commit 87a578df authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy
Browse files

schema: in a case of type mismatch print more informative message

If a field type is defined differently in index and in space format,
or in two or more indexes, then print more useful error message:
* What type of mismatch? - space vs index; index vs index;
* Name of mismatched field, if it is defined.

Besides, do not print, which type is defined 'previous' or not
'previous' - it is unknown during tuple_format creation.

Part of #2855
parent 56f970e1
No related branches found
No related tags found
No related merge requests found
......@@ -76,10 +76,10 @@ struct errcode_record {
/* 21 */_(ER_PROC_RET, "msgpack.encode: can not encode Lua type '%s'") \
/* 22 */_(ER_TUPLE_NOT_ARRAY, "Tuple/Key must be MsgPack array") \
/* 23 */_(ER_FIELD_TYPE, "Tuple field %u type does not match one required by operation: expected %s") \
/* 24 */_(ER_FIELD_TYPE_MISMATCH, "Ambiguous field type, field %u. Requested type is %s but the field has previously been defined as %s") \
/* 24 */_(ER_INDEX_PART_TYPE_MISMATCH, "Field %s has type '%s' in one index, but type '%s' in another") \
/* 25 */_(ER_SPLICE, "SPLICE error on field %u: %s") \
/* 26 */_(ER_UPDATE_ARG_TYPE, "Argument type in operation '%c' on field %u does not match field type: expected %s") \
/* 27 */_(ER_UNUSED1, "") \
/* 27 */_(ER_FORMAT_MISMATCH_INDEX_PART, "Field %s has type '%s' in space format, but type '%s' in index definition") \
/* 28 */_(ER_UNKNOWN_UPDATE_OP, "Unknown UPDATE operation") \
/* 29 */_(ER_UPDATE_FIELD, "Field %u UPDATE error: %s") \
/* 30 */_(ER_UNUSED2, "") \
......
......@@ -168,21 +168,31 @@ tuple_format_create(struct tuple_format *format, struct key_def * const *keys,
return -1;
}
field->is_key_part = true;
/*
* Check that there are no conflicts
* between index part types and space
* fields.
*/
if (field->type == FIELD_TYPE_ANY) {
field->type = part->type;
} else if (field->type != part->type) {
/**
* Check that there are no
* conflicts between index part
* types and space fields.
*/
diag_set(ClientError, ER_FIELD_TYPE_MISMATCH,
part->fieldno + TUPLE_INDEX_BASE,
field_type_strs[part->type],
field_type_strs[field->type]);
const char *name;
int fieldno = part->fieldno + TUPLE_INDEX_BASE;
if (field->name == NULL)
name = tt_sprintf("%d", fieldno);
else
name = tt_sprintf("'%s'", field->name);
int errcode;
if (! field->is_key_part)
errcode = ER_FORMAT_MISMATCH_INDEX_PART;
else
errcode = ER_INDEX_PART_TYPE_MISMATCH;
diag_set(ClientError, errcode, name,
field_type_strs[field->type],
field_type_strs[part->type]);
return -1;
}
field->is_key_part = true;
/*
* In the tuple, store only offsets necessary
* to access fields of non-sequential keys.
......
......@@ -840,13 +840,13 @@ pk = s:create_index('pk')
...
sk1 = s:create_index('sk1', { parts = { 2, 'unsigned' } })
---
- error: Ambiguous field type, field 2. Requested type is unsigned but the field has
previously been defined as string
- error: Field 'field2' has type 'string' in space format, but type 'unsigned' in
index definition
...
sk2 = s:create_index('sk2', { parts = { 3, 'number' } })
---
- error: Ambiguous field type, field 3. Requested type is number but the field has
previously been defined as scalar
- error: Field 'field3' has type 'scalar' in space format, but type 'number' in index
definition
...
-- Check space format conflicting with index parts.
sk3 = s:create_index('sk3', { parts = { 2, 'string' } })
......@@ -857,8 +857,8 @@ format[2].type = 'unsigned'
...
s:format(format)
---
- error: Ambiguous field type, field 2. Requested type is string but the field has
previously been defined as unsigned
- error: Field 'field2' has type 'unsigned' in space format, but type 'string' in
index definition
...
s:format()
---
......
......@@ -567,8 +567,7 @@ index = s:create_index('t1', { type = 'hash' })
-- field type contradicts field type of another index
index = s:create_index('t2', { type = 'hash', parts = { 1, 'string' }})
---
- error: Ambiguous field type, field 1. Requested type is string but the field has
previously been defined as unsigned
- error: Field 1 has type 'unsigned' in one index, but type 'string' in another
...
-- ok
index = s:create_index('t2', { type = 'hash', parts = { 2, 'string' }})
......@@ -841,8 +840,7 @@ s.index.primary:select{}
-- ambiguous field type
index = s:create_index('string', { type = 'tree', unique = false, parts = { 2, 'string'}})
---
- error: Ambiguous field type, field 2. Requested type is string but the field has
previously been defined as unsigned
- error: Field 2 has type 'unsigned' in one index, but type 'string' in another
...
-- create index on a non-existing field
index = s:create_index('nosuchfield', { type = 'tree', unique = true, parts = { 3, 'string'}})
......
......@@ -344,7 +344,7 @@ t;
- 'box.error.VINYL_MAX_TUPLE_SIZE : 139'
- 'box.error.LOAD_FUNCTION : 99'
- 'box.error.INVALID_XLOG : 74'
- 'box.error.READ_VIEW_ABORTED : 130'
- 'box.error.PRIV_NOT_GRANTED : 91'
- 'box.error.TRANSACTION_CONFLICT : 97'
- 'box.error.GUEST_USER_PASSWORD : 96'
- 'box.error.SEQUENCE_ACCESS_DENIED : 148'
......@@ -355,7 +355,7 @@ t;
- 'box.error.DROP_FUNCTION : 71'
- 'box.error.CFG : 59'
- 'box.error.NO_SUCH_FIELD : 37'
- 'box.error.CONNECTION_TO_SELF : 117'
- 'box.error.MORE_THAN_ONE_TUPLE : 41'
- 'box.error.FUNCTION_MAX : 54'
- 'box.error.ILLEGAL_PARAMS : 1'
- 'box.error.PARTIAL_KEY : 136'
......@@ -383,80 +383,81 @@ t;
- 'box.error.FUNCTION_EXISTS : 52'
- 'box.error.UPDATE_ARG_TYPE : 26'
- 'box.error.CROSS_ENGINE_TRANSACTION : 81'
- 'box.error.IDENTIFIER : 70'
- 'box.error.FORMAT_MISMATCH_INDEX_PART : 27'
- 'box.error.injection : table: <address>
- 'box.error.NO_SUCH_ENGINE : 57'
- 'box.error.COMMIT_IN_SUB_STMT : 122'
- 'box.error.injection : table: <address>
- 'box.error.NULLABLE_MISMATCH : 153'
- 'box.error.LAST_DROP : 15'
- 'box.error.PROC_RET : 21'
- 'box.error.LAST_DROP : 15'
- 'box.error.SPACE_FIELD_IS_DUPLICATE : 149'
- 'box.error.DECOMPRESSION : 124'
- 'box.error.CREATE_SEQUENCE : 142'
- 'box.error.CREATE_USER : 43'
- 'box.error.SPACE_FIELD_IS_DUPLICATE : 149'
- 'box.error.INSTANCE_UUID_MISMATCH : 66'
- 'box.error.SEQUENCE_OVERFLOW : 147'
- 'box.error.INSTANCE_UUID_MISMATCH : 66'
- 'box.error.INJECTION : 8'
- 'box.error.SYSTEM : 115'
- 'box.error.KEY_PART_IS_TOO_LONG : 118'
- 'box.error.INJECTION : 8'
- 'box.error.USER_MAX : 56'
- 'box.error.NO_SUCH_SAVEPOINT : 61'
- 'box.error.RELOAD_CFG : 58'
- 'box.error.TRUNCATE_SYSTEM_SPACE : 137'
- 'box.error.NO_SUCH_SAVEPOINT : 61'
- 'box.error.VY_QUOTA_TIMEOUT : 135'
- 'box.error.READ_VIEW_ABORTED : 130'
- 'box.error.WRONG_INDEX_OPTIONS : 108'
- 'box.error.INVALID_VYLOG_FILE : 133'
- 'box.error.INDEX_FIELD_COUNT_LIMIT : 127'
- 'box.error.UNSUPPORTED_INDEX_FEATURE : 112'
- 'box.error.FIELD_TYPE_MISMATCH : 24'
- 'box.error.RELOAD_CFG : 58'
- 'box.error.INVALID_XLOG_TYPE : 125'
- 'box.error.USER_MAX : 56'
- 'box.error.PROTOCOL : 104'
- 'box.error.TUPLE_NOT_ARRAY : 22'
- 'box.error.KEY_PART_COUNT : 31'
- 'box.error.ALTER_SPACE : 12'
- 'box.error.ACTIVE_TRANSACTION : 79'
- 'box.error.EXACT_FIELD_COUNT : 38'
- 'box.error.DROP_SEQUENCE : 144'
- 'box.error.ITERATOR_TYPE : 72'
- 'box.error.PROC_LUA : 32'
- 'box.error.DROP_SPACE : 11'
- 'box.error.INVALID_MSGPACK : 20'
- 'box.error.UPSERT_UNIQUE_SECONDARY_KEY : 105'
- 'box.error.UNKNOWN_REQUEST_TYPE : 48'
- 'box.error.SUB_STMT_MAX : 121'
- 'box.error.INDEX_FIELD_COUNT : 39'
- 'box.error.SPACE_EXISTS : 10'
- 'box.error.MORE_THAN_ONE_TUPLE : 41'
- 'box.error.ROLE_NOT_GRANTED : 92'
- 'box.error.UPDATE_INTEGER_OVERFLOW : 95'
- 'box.error.NO_SUCH_SPACE : 36'
- 'box.error.WRONG_INDEX_PARTS : 107'
- 'box.error.UPDATE_INTEGER_OVERFLOW : 95'
- 'box.error.PRIV_NOT_GRANTED : 91'
- 'box.error.UNSUPPORTED : 5'
- 'box.error.REPLICASET_UUID_MISMATCH : 63'
- 'box.error.UPDATE_FIELD : 29'
- 'box.error.INDEX_EXISTS : 85'
- 'box.error.COMPRESSION : 119'
- 'box.error.SPACE_ACCESS_DENIED : 55'
- 'box.error.INDEX_EXISTS : 85'
- 'box.error.UNKNOWN_REQUEST_TYPE : 48'
- 'box.error.TUPLE_FORMAT_LIMIT : 16'
- 'box.error.DROP_SPACE : 11'
- 'box.error.PROC_LUA : 32'
- 'box.error.ITERATOR_TYPE : 72'
- 'box.error.DROP_PRIMARY_KEY : 17'
- 'box.error.NULLABLE_PRIMARY : 152'
- 'box.error.NO_SUCH_SEQUENCE : 145'
- 'box.error.INVALID_ORDER : 68'
- 'box.error.INVALID_UUID : 64'
- 'box.error.UNSUPPORTED : 5'
- 'box.error.IDENTIFIER : 70'
- 'box.error.TIMEOUT : 78'
- 'box.error.REPLICA_MAX : 73'
- 'box.error.TUPLE_FORMAT_LIMIT : 16'
- 'box.error.NO_SUCH_ROLE : 82'
- 'box.error.UNKNOWN : 0'
- 'box.error.MISSING_REQUEST_FIELD : 69'
- 'box.error.MISSING_SNAPSHOT : 93'
- 'box.error.WRONG_SPACE_OPTIONS : 111'
- 'box.error.READONLY : 7'
- 'box.error.ACCESS_DENIED : 42'
- 'box.error.UPSERT_UNIQUE_SECONDARY_KEY : 105'
- 'box.error.NO_CONNECTION : 77'
- 'box.error.UNKNOWN : 0'
- 'box.error.INVALID_XLOG_ORDER : 76'
- 'box.error.WRONG_SCHEMA_VERSION : 109'
- 'box.error.ROLLBACK_IN_SUB_STMT : 123'
- 'box.error.INVALID_MSGPACK : 20'
- 'box.error.PROTOCOL : 104'
- 'box.error.INVALID_XLOG_TYPE : 125'
- 'box.error.UNSUPPORTED_INDEX_FEATURE : 112'
- 'box.error.CONNECTION_TO_SELF : 117'
- 'box.error.INDEX_PART_TYPE_MISMATCH : 24'
- 'box.error.FUNCTION_ACCESS_DENIED : 53'
...
test_run:cmd("setopt delimiter ''");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment