Commit 1abc6975 authored by zYne's avatar zYne

updated index docs

parent 5744f045
<?php ?> <?php ?>
You can add indexes by simple calling Doctrine_Record::option('index', $definition) where $definition is the You can add indexes by simple calling Doctrine_Record::index('indexName', $definition) where $definition is the
definition array. The structure of the definition array is as follows: definition array.
<div class='sql'>
<pre>
[ indexName1 => [col1 => [col1-options], ... , colN => [colN-options]
indexName2 => ...
indexNameN => ]
</pre>
</div>
<br \><br \> <br \><br \>
An example of adding a simple index to field called 'name': An example of adding a simple index to field called 'name':
<br \><br \> <br \><br \>
...@@ -21,7 +14,7 @@ class IndexTest extends Doctrine_Record ...@@ -21,7 +14,7 @@ class IndexTest extends Doctrine_Record
} }
public function setUp() public function setUp()
{ {
\$this->option('index', array('myindex' => 'name')); \$this->index('myindex', array('fields' => 'name');
} }
} }
?>"); ?>");
...@@ -40,7 +33,7 @@ class MultiColumnIndexTest extends Doctrine_Record ...@@ -40,7 +33,7 @@ class MultiColumnIndexTest extends Doctrine_Record
} }
public function setUp() public function setUp()
{ {
\$this->option('index', array('myindex' => array('name', 'code'))); \$this->index('myindex', array('fields' => array('name', 'code')));
} }
} }
?>"); ?>");
...@@ -60,10 +53,8 @@ class MultipleIndexTest extends Doctrine_Record ...@@ -60,10 +53,8 @@ class MultipleIndexTest extends Doctrine_Record
} }
public function setUp() public function setUp()
{ {
\$this->option('index', \$this->index('myindex', array('fields' => array('name', 'code')));
array('myindex' => array('name', 'code') \$this->index('ageindex', array('fields' => array('age'));
'ageindex' => 'age')
);
} }
} }
?>"); ?>");
......
...@@ -2,19 +2,43 @@ ...@@ -2,19 +2,43 @@
Doctrine offers many index options, some of them being db-specific. Here is a full list of availible options: Doctrine offers many index options, some of them being db-specific. Here is a full list of availible options:
<div class='sql'> <div class='sql'>
<pre> <pre>
unique => boolean(true / false)
whether or not the index is unique index
sorting => string('ASC' / 'DESC') sorting => string('ASC' / 'DESC')
what kind of sorting does the index use (ascending / descending) what kind of sorting does the index use (ascending / descending)
length => integer
index length (only some drivers support this)
primary => boolean(true / false) primary => boolean(true / false)
whether or not the index is primary index whether or not the index is primary index
fulltext => boolean(true / false) type => string('unique', -- supported by most drivers
whether or not the specified index is a FULLTEXT index (only availible on Mysql) 'fulltext', -- only availible on Mysql driver
'gist', -- only availible on Pgsql driver
gist => boolean(true / false) 'gin') -- only availible on Pgsql driver
whether or not the specified index is a GiST index (only availible on Pgsql)
</pre> </pre>
</div> </div>
<?php
renderCode("<?php
class MultipleIndexTest extends Doctrine_Record
{
public function setTableDefinition()
{
\$this->hasColumn('name', 'string');
\$this->hasColumn('code', 'string');
\$this->hasColumn('age', 'integer');
}
public function setUp()
{
\$this->index('myindex', array(
'fields' => array(
'name' =>
array('sorting' => 'ASC',
'length' => 10),
'code'),
'type' => 'unique',
));
}
}
?>");
?>
...@@ -5,4 +5,5 @@ The larger the table, the more this consumes time. If the table has an index for ...@@ -5,4 +5,5 @@ The larger the table, the more this consumes time. If the table has an index for
can quickly determine the position to seek to in the middle of the data file without having to look at all the data. can quickly determine the position to seek to in the middle of the data file without having to look at all the data.
If a table has 1,000 rows, this is at least 100 times faster than reading rows one-by-one. If a table has 1,000 rows, this is at least 100 times faster than reading rows one-by-one.
<br \><br \> <br \><br \>
You should *<b>always</b>* use indexes for the fields that are used in sql where conditions. Indexes come with a cost as they slow down the inserts and updates. However, in general you
should *<b>always</b>* use indexes for the fields that are used in sql where conditions.
...@@ -13,10 +13,8 @@ class Article ...@@ -13,10 +13,8 @@ class Article
} }
public function setUp() public function setUp()
{ {
\$this->option('index', \$this->index('content', array('fields' => 'content',
array('content' => 'type' => 'fulltext'));
array('content' =>
array('fulltext' => true));
} }
} }
?>"); ?>");
...@@ -109,6 +109,11 @@ $menu = array('Getting started' => ...@@ -109,6 +109,11 @@ $menu = array('Getting started' =>
'Default values', 'Default values',
'Enum emulation', 'Enum emulation',
), ),
'Working with existing databases' => array(
'Introduction',
'Making the first import',
'Import options',
),
'Record identifiers' => array( 'Record identifiers' => array(
'Introduction', 'Introduction',
...@@ -122,6 +127,8 @@ $menu = array('Getting started' => ...@@ -122,6 +127,8 @@ $menu = array('Getting started' =>
'Index options', 'Index options',
'Special indexes', 'Special indexes',
), ),
), ),
'Connection management' => 'Connection management' =>
array( array(
...@@ -149,6 +156,9 @@ $menu = array('Getting started' => ...@@ -149,6 +156,9 @@ $menu = array('Getting started' =>
'Enum', 'Enum',
'Gzip', 'Gzip',
), ),
'Foreign keys' => array(
'Introduction',
),
/** /**
'Column attributes' => array( 'Column attributes' => array(
'Introduction', 'Introduction',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment