Issue Details (XML | Word | Printable)

Key: ZF-1037
Type: Bug Bug
Status: Resolved Resolved
Resolution: Duplicate
Priority: Major Major
Assignee: Bill Karwin
Reporter: Joseph Wilk
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

MS SQL Server: PDO limit() function does not work when count+offset > number of rows in table

Created: 12/Mar/07 06:05 AM   Updated: 05/Jul/07 02:43 PM   Resolved: 19/May/07 02:50 PM
Component/s: Zend_Db
Affects Version/s: 0.8.0
Fix Version/s: 1.0.0 RC1

Time Tracking:
Not Specified

Issue Links:
Duplicate
 


 Description  « Hide

MSSQL PDO limit( function.

The principle discussed and referenced within the code does not work in all cases.

http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html

Example:

Consider a table view_content_admin with 14 record within it. limit is called with
offset:10
count:10

SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 content.* FROM view_content_admin ORDER BY content.name ASC) AS select_limit_rev ORDER BY name DESC ) AS select_limit ORDER BY name ASC

Given the logic specified in the above query records 5-14 are produced rather than the desired 10-14.

The core logic of the SQL theory splits into creating two sets:
1.count+offset
2.count.

When the 'count+offset' is set is larger than that of the number of records within the table/result there are not enough rows in the set in order for the second set 'count' to capture the desired rows. It will always capture more results than desired. The set 'count' needs to take account of the number rows within the table/result in order to correclty select the limit,offset.

1.count+offset

so if count+offset > rowCount

2. (rowCount - offset)+1

The difficult task is knowing the number of rows for a select statement. This is impossible to gather in all contexts as the limit function may be called before other where clauses are added. And having to run the query to get the rowCount has significant performance issues.

So in summary
When the set of results is smaller than count+offset the rows returned do not match those expect from the offset and limit values.
It seems impossible for the limit function to work in its current guise.



Sort Order: Ascending order - Click to sort in descending order
Joseph Wilk made changes - 12/Mar/07 06:08 AM
Field Original Value New Value
Description MSSQL PDO limit( function.

The principle discussed and referenced within the code does not work in all cases.

http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html

Example:

Consider a table view_content_admin with 14 record within it. limit is called with
offset:10
count:10

SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 content.* FROM view_content_admin ORDER BY content.name ASC) AS select_limit_rev ORDER BY name DESC ) AS select_limit ORDER BY name ASC

Given the logic specified in the above query records 5-14 are produced rather than the desired 10-14.

The core logic of the SQL theory splits into creating two sets:
1.count+offset
2.count.

When the 'count+offset' is set is larger than that of the number of records within the table/result there are not enough rows in the set in order for the second set 'count' to capture the desired rows. It will always capture more results than desired. The set 'count' needs to take account of the number rows within the table in order to correclty select the limit,offset.


1.count+offset

So if count+offset > rowCount

2. (rowCount - offset)+1

The difficult task is knowing the number of rows for a select statement. This is impossible to gather in all contexts as the limit function may be called before other where clauses are added. And having to run the query to get the rowCount has significant performance issues.

So in summary
When the set of results is smaller than count+offset the rows returned do not match those expect from the offset and limit values.
It seems impossible for the limit function to work in its current guise.
MSSQL PDO limit( function.

The principle discussed and referenced within the code does not work in all cases.

http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html

Example:

Consider a table view_content_admin with 14 record within it. limit is called with
offset:10
count:10

SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 content.* FROM view_content_admin ORDER BY content.name ASC) AS select_limit_rev ORDER BY name DESC ) AS select_limit ORDER BY name ASC

Given the logic specified in the above query records 5-14 are produced rather than the desired 10-14.

The core logic of the SQL theory splits into creating two sets:
1.count+offset
2.count.

When the 'count+offset' is set is larger than that of the number of records within the table/result there are not enough rows in the set in order for the second set 'count' to capture the desired rows. It will always capture more results than desired. The set 'count' needs to take account of the number rows within the table/result in order to correclty select the limit,offset.


1.count+offset

so if count+offset > rowCount

2. (rowCount - offset)+1

The difficult task is knowing the number of rows for a select statement. This is impossible to gather in all contexts as the limit function may be called before other where clauses are added. And having to run the query to get the rowCount has significant performance issues.

So in summary
When the set of results is smaller than count+offset the rows returned do not match those expect from the offset and limit values.
It seems impossible for the limit function to work in its current guise.
Bill Karwin made changes - 12/Mar/07 10:51 AM
Assignee Bill Karwin [ bkarwin ]
Bill Karwin made changes - 17/Apr/07 04:45 PM
Workflow jira [ 11207 ] Framework [ 11635 ]
Bill Karwin made changes - 18/Apr/07 01:39 PM
Workflow Framework [ 11635 ] jira [ 12888 ]
Bill Karwin made changes - 18/Apr/07 02:47 PM
Workflow jira [ 12888 ] Framework [ 14184 ]
Bill Karwin made changes - 12/May/07 12:33 PM
Status Open [ 1 ] Postponed [ 10000 ]
Bill Karwin made changes - 19/May/07 02:49 PM
Status Postponed [ 10000 ] Open [ 1 ]
Bill Karwin made changes - 19/May/07 02:50 PM
Link This issue duplicates ZF-853 [ ZF-853 ]
Bill Karwin made changes - 19/May/07 02:50 PM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 1.0.0 RC1 [ 10023 ]
Resolution Duplicate [ 3 ]
Bill Karwin made changes - 02/Jul/07 07:16 PM
Workflow Framework [ 14184 ] Zend Framework [ 16944 ]
Bill Karwin made changes - 05/Jul/07 02:43 PM
Workflow Zend Framework [ 16944 ] Framework [ 18639 ]