소스 검색

ZF-5561: setRowCount() needs more documentation

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16153 44c647ce-9c0f-0410-b52a-842ac1e357ba
norm2782 16 년 전
부모
커밋
52563f514d
1개의 변경된 파일39개의 추가작업 그리고 0개의 파일을 삭제
  1. 39 0
      documentation/manual/en/module_specs/Zend_Paginator-Usage.xml

+ 39 - 0
documentation/manual/en/module_specs/Zend_Paginator-Usage.xml

@@ -175,6 +175,45 @@ $this->view->paginator = $paginator;
 ]]></programlisting>
         </para>
     </sect2>
+    
+    <sect2 id="zend.paginator.usage.dbselect">
+        <title>The DbSelect and DbTableSelect adapter</title>
+        <para>
+            The usage of most adapters is pretty straight-forward. However, the
+            database adapters require a more detailed explanation. Contrary to popular
+            believe, these adapters do NOT fetch all records from the database in order to count them.
+            Instead, the adapters manipulates the original query to produce the corresponding
+            COUNT query. Paginator then executes that COUNT query to get the number of rows.
+            This does require an extra round-trip to the database, but this is many times
+            faster than fetching an entire result set and using count(). Especially with
+            large collections of data.
+        </para>
+        
+        <para>
+            The database adapters will try and build the most efficient query that will execute
+            on pretty much all modern databases. However, depending on your database or even your
+            own schema setup, there might be more efficient ways to get a rowcount. For this scenario
+            the database adapters allow you to set a custom COUNT query. For example,
+            if you keep track of the count of blog posts in a separate table, you could achieve a
+            faster count query with the following setup:  
+        </para>
+        
+        <programlisting language="php"><![CDATA[
+$adapter = new Zend_Paginator_Adapter_DbSelect($db->select()->from('posts'));
+$adapter->setRowCount(
+    $db->select()->from('item_counts', array(Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => 'post_count')) 
+)
+
+$paginator = new Zend_Paginator($adapter);
+]]></programlisting>
+    
+        <para>
+            This approach will probably not give you a huge performance gain on
+            small collections and/or simple select queries. However, with complex
+            queries and large collections, a similar approach could give you a 
+            significant performance boost.
+        </para>
+    </sect2>
 
     <sect2 id="zend.paginator.rendering">
         <title>Rendering pages with view scripts</title>