1
0
Fork 0
arangodb/Doxygen/doc/IndexHash.html

79 lines
5.1 KiB
HTML

<html><head><title>ArangoDB Manual</title> <style media="screen" type="text/css" style="display:none">body{background-color:white;font:13px Helvetica,arial,freesans,clean,sans-serif;line-height:1.4;color:#333;}#access{font-size:16px;margin-left:12px;display:block;margin-left:10px;margin-right:10px;background-color:#F3F1EE!important;}#access a{border-right:1px solid #DBDEDF;color:#A49F96;display:block;line-height:38px;padding:0 10px;text-decoration:none;}#navigation ul{text-transform:uppercase;list-style:none;margin:0;}#navigation li{float:left;position:relative;}#container{width:920px;margin:0 auto;}a{color:#4183C4;text-decoration:none;}.contents h2{font-size:24px;border-bottom:1px solid #CCC;color:black;}.contents h1{font-size:33px;border-bottom:1px solid #CCC;color:black;}.clearfix:after{content:".";display:block;clear:both;font-size:0;height:0;visibility:hidden;}/**/ *:first-child+html .clearfix{min-height:0;}/**/ * html .clearfix{height:1%;}</style></head><body><div id="container"><img src="images/logo_arangodb.png" width="397" height="67" alt="ArangoDB"><div id="access" role="navigation"><div id="navigation"><ul id="menu-ahome" class="menu"><li><a href="Home.html">Table of contents</a></li> <li><a href="http://www.arangodb.org">ArangoDB homepage</a></li></ul></div><div class="clearfix"></div></div><div>
<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div class="header">
<div class="headertitle">
<h1>Hash Indexes </h1> </div>
</div>
<div class="contents">
<div class="textblock"><p>This is an introduction to ArangoDB's hash indexes.</p>
<hr/>
<ul>
<li>
<a class="el" href="IndexHash.html">Hash Indexes</a> <ul>
<li>
<a class="el" href="IndexHash.html#IndexHashIntro">Hash Indexes</a> </li>
<li>
<a class="el" href="IndexHash.html#IndexHashShell">Accessing Hash Indexes from the Shell</a> <ul>
<li>
<a class="el" href="IndexHash.html#IndexHashShellEnsureUniqueConstraint">collection.ensureUniqueConstraint</a> </li>
<li>
<a class="el" href="IndexHash.html#IndexHashShellEnsureHashIndex">collection.ensureHashIndex</a> </li>
</ul>
</li>
</ul>
</li>
</ul>
<hr/>
<h2><a class="anchor" id="IndexHashIntro"></a>
Hash Indexes</h2>
<p>It is possible to define a hash index on one or more attributes (or paths) of a documents. This hash is then used in queries to locate documents in O(1) operations. If the hash is unique, then no two documents are allowed to have the same set of attribute values.</p>
<h2><a class="anchor" id="IndexHashShell"></a>
Accessing Hash Indexes from the Shell</h2>
<p><a class="anchor" id="IndexHashShellEnsureUniqueConstraint"></a> <hr/>
<code><b>ensureUniqueConstraint(<em>field1</em>, <em>field2</em>, ..., <em>fieldn</em>)</b></code><hr/>
Creates a unique hash index on all documents using <em>field1</em>, <em>field2</em>, ... as attribute paths. At least one attribute path must be given.</p>
<p>When a unique constraint is in effect for a collection, then all documents which contain the given attributes must differ in the attribute values. Creating a new document or updating a document will fail, if the uniqueness is violated. If any attribute value is null for a document, this document is ignored by the index.</p>
<p>Note that non-existing attribute paths in a document are treat as if the value were <code>null</code>.</p>
<p>In case that the index was successfully created, the index identifier is returned.</p>
<p><b>Examples</b><br/>
</p>
<div class="fragment"><pre class="fragment">arango&gt; db.four.ensureUniqueConstraint("a", "b.c");
{ "id" : "164405/1147445", "unique" : true, "type" : "hash", "fields" : ["a", "b.c"], "isNewlyCreated" : true }
arango&gt; db.four.save({ a : 1, b : { c : 1 } });
{ "_id" : "164405/1868341", "_rev" : 1868341 }
arango&gt; db.four.save({ a : 1, b : { c : 1 } });
JavaScript exception in file '(arango)' at 1,9: [ArangoError 1210: cannot save document]
!db.four.save({ a : 1, b : { c : 1 } });
! ^
stacktrace: [ArangoError 1210: cannot save document]
at (arango):1:9
arango&gt; db.four.save({ a : 1, b : { c : null } });
{ "_id" : "164405/2196021", "_rev" : 2196021 }
arango&gt; db.four.save({ a : 1 });
{ "_id" : "164405/2196023", "_rev" : 2196023 }
</pre></div> <p><a class="anchor" id="IndexHashShellEnsureHashIndex"></a> <hr/>
<code><b>ensureHashIndex(<em>field1</em>, <em>field2</em>, ..., <em>fieldn</em>)</b></code><hr/>
Creates a unique hash index on all documents using <em>field1</em>, <em>field2</em>, ... as attribute paths. At least one attribute path must be given.</p>
<p>Note that non-existing attribute paths in a document are treat as if the value were <code>null</code>.</p>
<p>In case that the index was successfully created, the index identifier is returned.</p>
<p><b>Examples</b><br/>
</p>
<div class="fragment"><pre class="fragment">arango&gt; db.test.ensureHashIndex("a");
{ "id" : "4873815/5922391", "unique" : false, "type" : "hash", "fields" : ["a"], "isNewlyCreated" : true }
arango&gt; db.test.save({ a : 1 });
{ "_id" : "4873815/6381143", "_rev" : 6381143 }
arango&gt; db.test.save({ a : 1 });
{ "_id" : "4873815/6446679", "_rev" : 6446679 }
arango&gt; db.test.save({ a : null });
{ "_id" : "4873815/6708823", "_rev" : 6708823 }
</pre></div> </div></div>
</div></body></html>