Comments (6)
This is working in production fairly well.
protected function compileTableExpression($sql, $constraint, $query)
{
if ($query->limit == 1 && is_null($query->offset)) {
return "select * from ({$sql}) where rownum {$constraint}";
}
// Apply ROW_NUMBER() for pagination
$orderBy = $this->compileOrders($query, $query->orders);
// If no ORDER BY is specified, use ROWID for ordering
if (empty($orderBy)) {
$orderBy = "order by ROWID";
}
return "select * from (
select t1.*, row_number() over ({$orderBy}) as row_num
from ({$sql}) t1
) where row_num {$constraint}";
}
Example query generated, down from 20s to 650ms:
select * from (
select t1.*, row_number() over (order by ROWID) as row_num
from (select * from "INV"."ITM" where "ITM_CD" is not null and "DROP_DT" is null) t1
) where row_num between 126 and 150
Implemented in AppServiceProvider like so:
class_alias (App\Database\Query\Grammars\OracleGrammar::class, \Yajra\Oci8\Query\Grammars\OracleGrammar::class);
from laravel-oci8.
Welcome! We literally just override this function.
It would be worth testing this out though before a PR, as although it works for us, it may encounter other scenarios where it doesn't (i don't know the full scope of the package).
PR submitted: #878
from laravel-oci8.
Just FYI, I tried implementing @alexc-jeromes override in our app, and it was great for a slow query issue we were having, but unfortunately we got errors in other queries, specifically ones with subqueries. For instance, we got ORA-01445 in a few places.
I'm doing a lot of research, and I'm wondering if modifying compileRowConstraint()
might be better, using OFFSET
and FETCH
? I'm not an Oracle expert, by any means...
from laravel-oci8.
@alexc-jeromes thank you for taking your time in reviewing this issue. Can you please submit a PR, I will review it asap.
from laravel-oci8.
@mixaster Yeh i suspected that might be the case. We're using it with quite simple queries and the solution is only needed for record browsing without complexity, so it will need a bit of tweaking. I can see the PR failed too. I'm not heavy enough into OCI8 to know the best way to do Oracle-specific driver work. We're moving to PG thankfully.
from laravel-oci8.
This issue is stale because it has been open for 30 days with no activity.
from laravel-oci8.
Related Issues (20)
- Laravel 11 support is on the road? HOT 5
- [11.x] This database engine does not support inserting while ignoring errors.
- [11.x] Error Code : 942 Error Message : ORA-00942, Sessions table HOT 1
- Support PHP 8.3 With Laravel 10.x HOT 1
- Error LogicException This database driver does not support modifying columns HOT 1
- `Schema::dropIfExists()` not working in 11.2.2+ HOT 2
- Upgrading laravel/framework v11.15.0 fails migration containing table update (ORA-01430) HOT 1
- Problem with sequence with long table name HOT 3
- Order "compileColumnExists" by column_id HOT 1
- Problem with "wrapTable" function using it in "compileUpsert" HOT 2
- Lock for update implementation on 9x HOT 3
- Problem with ORM update HOT 2
- ORM OCI8 - ORA-00923: FROM keyword not found where expected Position HOT 3
- @gabrieloliverio, setting a custom sequence is not yet fully functional. ATM, I think you need to set the id manually by getting the next value of the sequence. See https://github.com/yajra/laravel-oci8/wiki/Oracle-Sequence. HOT 1
- Self relationship generate Error ORA-00904: "LARAVEL_RESERVED_0" HOT 3
- The after method doesn't work, the column is added at the end HOT 2
- Missing merged branch inside new release HOT 2
- [v11.6.1] Randomly Error: ORA-00907: missing right parenthesis HOT 2
- ORA-02396: exceeded maximum idle time, please connect again HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-oci8.