Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14343

[Feature] Database table size estimation

$
0
0
When paginating an API for example, it is often crucial to know how many pages you have (or how many rows you have) so you will show the correct amount of pages, show infinite scrolling when needed, etc..

The simplest, DB engine agnostic solution would be:
select("COUNT(1) as c")->from("table")->where()->where()....->where()->group()
(No order, no limit)

This way is very naive, and can take alot of time sometimes.

Feature request:
DB to have:
$this->db->estimate();


Simplest? will execute the prepared query, with no limit and no order
Better? 
- MySQL has an efficient way of calculating, selecting `SQL_CALC_FOUND_ROWS`
- Postgre has it's own solution
and I guess every DB has it's own.

So the flow would be something like:
$this->db->select("something")->from("somewhere")->where("some", "value")->order_by('key', 'asc')->limit(10, 10)->estimate();
$query = $this->db->get();
$result = $query->result();
$estimation = $query->estimation();


I think it is very functional.

If my explaination is not great, please et me know how to fix it Smile

Viewing all articles
Browse latest Browse all 14343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>