<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="docs.css"> <!--[if gte IE 5]> <link href="docs_ie.css" rel="stylesheet" type="text/css"> <![endif]--> </head> <body><div id="pagecontainer"><table><tr><td width="5"> </td><td><a name="Indexes"></a><br> <a name="outline228"></a><br><h1>15. Indexes</h1><br> db4o allows to index fields to provide maximum querying performance. To request an index to be created, you would issue the following API method call in your global <a href="Configuration.html#Configuration">db4o configuration method</a> before you open an IObjectContainer/IObjectServer:<br> <br> <table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="lg"> <code>// assuming<br> class Foo<br> {<br> String bar;<br> }<br> <br> ICommonConfiguration#ObjectClass(typeof(Foo)).ObjectField("bar").Indexed(true);</code></td></tr></table> <br> <br> If the configuration is set in this way, an index on the Foo#bar field will be created (if not present already) the next time you open an<br> IObjectContainer/IObjectServer and you use the Foo class the first time<br> in your application.<br> <br> Contrary to all other <a href="Configuration.html#Configuration">configuration calls</a> indexes - once created - will remain in a database even if the index configuration call is not issued before opening an IObjectContainer/IObjectServer. <br> <br> To drop an index you would also issue a configuration call in your db4o configuration method:<br> <table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="lg"> <code>ICommonConfiguration#ObjectClass(typeof(Foo)).ObjectField("bar").Indexed(false);</code></td></tr></table> <br> Actually dropping the index will take place the next time the respective class is used.<br> <br> db4o will tell you when it creates and drops indexes, if you choose a message level of 1 or higher:<br> <table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="lg"> <code>ICommonConfiguration#MessageLevel(1);</code></td></tr></table> <br> <br> For creating and dropping indexes on large amounts of objects there are two possible strategies:<br> (1) Import all objects with indexing off, configure the index and reopen the ObjectContainer/ObjectServer.<br> (2) Import all objects with indexing turned on and commit regularly for a fixed amount of objects (~10,000).<br> <br> (1) will be faster.<br> (2) will keep memory consumption lower.<br> <br><br><div id="footer"><p align="center">Do you have any questions, suggestions or feedback? Ask your questions in the <a href="http://developer.db4o.com/Forums.aspx" target=_top>db4o forums</a>. Join the <a href="http://developer.db4o.com" target=_top>db4o community</a> for addional resources and news.<br><br><a href="http://www.db4o.com/" target=_top><small>www.db4o.com</small></a></p>.</div><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></td></tr></table></div></body></html>