2016-09-30 5 views
0

빠른 질문 : ArangoDB에서 고유 인덱스 (예 : 고유 해시 인덱스)를 만들면 ArangoDB가 해당 특성의 고유성을 확인합니까 아니면 고유하다고 말했기 때문에 가정합니까? 고유 인덱스를 만들기 전에 데이터의 고유성을 확인하기 위해 유효성 검사 단계를 거쳐야하는지 궁금합니다.ArangoDB 고유 인덱스 유효성 검사

답변

3

알다시피 ArangoDB는 인덱스를 사용하기 전에 인덱스를 생성합니다. 당신이 경우에 따라서

127.0.0.1:[email protected]_system> db._drop("c") 
127.0.0.1:[email protected]_system> c = db._create("c") 
[ArangoCollection 315, "c" (type document, status loaded)] 

127.0.0.1:[email protected]_system> c.ensureIndex({ 
...>"type":"skiplist","unique":true,"fields":["abc"]}) 
{ 
    "id" : "c/318", 
    "type" : "skiplist", 
    "fields" : [ 
    "abc" 
    ], 
    "unique" : true, 
    "sparse" : false, 
    "isNewlyCreated" : true, 
    "code" : 201 
} 

127.0.0.1:[email protected]_system> c.insert({"abc":1}) 
{ 
    "_id" : "c/330", 
    "_key" : "330", 
    "_rev" : "_T1n-B2S---" 
} 

127.0.0.1:[email protected]_system> c.insert({"abc":1}) 
JavaScript exception in file '.../arangosh.js' at 97,7: 
ArangoError 1210: cannot create document, unique constraint violated 
!  throw error; 
! ^
stacktrace: ArangoError: cannot create document, unique constraint violated 
at Object.exports.checkRequestResult (.../arangosh.js:95:21) 
at ArangoCollection.save.ArangoCollection.insert 
    (.../arango-collection.js:978:14) 
at <shell command>:1:3 

: 당신이 고유 제한 조건을 위반하는 문서를 삽입 할 경우이 무엇을

127.0.0.1:[email protected]_system> c = db._create("c") 
[ArangoCollection 169, "c" (type document, status loaded)] 
127.0.0.1:[email protected]_system> c.insert({"abc":1}) 
{ 
    "_id" : "c/172", 
    "_key" : "172", 
    "_rev" : "_T1m73_m---" 
} 
127.0.0.1:[email protected]_system> c.insert({"abc":1}) 
{ 
    "_id" : "c/176", 
    "_key" : "176", 
    "_rev" : "_T1m748K---" 
} 
127.0.0.1:[email protected]_system> c.ensureIndex(
...> {"type":"hash","unique":true,"fields":["abc"]}) 
JavaScript exception in file '.../arangosh.js' at 97,7: 
ArangoError 1210: unique constraint violated 
!  throw error; 
! ^
stacktrace: ArangoError: unique constraint violated 
    at Object.exports.checkRequestResult (.../arangosh.js:95:21) 
    at ArangoCollection.ensureIndex (.../arango-collection.js:733:12) 
    at <shell command>:1:3 

127.0.0.1:[email protected]_system> c.ensureIndex(
...> {"type":"skiplist","unique":true,"fields":["abc"]}) 
JavaScript exception in file '.../arangosh.js' at 97,7: 
ArangoError 1210: unique constraint violated 
!  throw error; 
! ^
stacktrace: ArangoError: unique constraint violated 
    at Object.exports.checkRequestResult (.../arangosh.js:95:21) 
    at ArangoCollection.ensureIndex (.../arango-collection.js:733:12) 
    at <shell command>:1:3 

유사 : 그것은 고유성을 보장하기 위해 실패하면 , 그것은 예외가 발생합니다 응용 프로그램을 설치하는 동안 문서를 삽입하십시오 (성능상의 이유로 접근 가능). 나중에 이러한 색인을 작성할 때 발생할 수있는 예외를 처리해야합니다.

+0

감사합니다. 그건 내 질문에 대한 답변. 데이터를 추가 한 후 성능을 높이고 인덱스를 생성 했으므로 삽입하는 동안 인덱싱을 일시적으로 해제 한 다음 끝에 인덱스를 업데이트 할 수 있습니까? 나는 이것이 ACID에 위배된다고 생각하지만 괜찮습니다. 엄청난 수의 가장자리를 삽입해야합니다. 관계 정의 자체를 생성하면 인덱싱 (많은 수의 대단위 조인)으로 많은 이점을 얻을 수 있지만 인덱싱을 통해 삽입 작업이 상당히 느려지므로 성능 이점이 사라집니다. –