[Django] #26506: Implement support for TABLESAMPLE

25 views
Skip to first unread message

Django

unread,
Apr 15, 2016, 6:34:53 AM4/15/16
to django-...@googlegroups.com
#26506: Implement support for TABLESAMPLE
----------------------------------------------+-------------------------
Reporter: pope1ni | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords: tablesample
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+-------------------------
PostgreSQL 9.5 added support for the `TABLESAMPLE` feature from the
SQL:2003 standard. It would be useful to add support for this to Django.

For PostgreSQL it would also be good to support the custom
`tsm_system_rows` and `tsm_system_time` extensions to provide
`SYSTEM_ROWS` and `SYSTEM_TIME` in addition to `BERNOULLI` and `SYSTEM`
defined in the standard.

Note that `TABLESAMPLE` can also be used to update or delete only a sample
of rows.

I suggest adding `.tablesample(method, value[, seed])` to `QuerySet`
where:

- `method` is one of `bernoulli`, `system`, `rows` or `time`,
- `value` is the percentage, count or time argument to pass,
- `seed` is the value to use for the `REPEATABLE` option.

Note that `seed` should not be allowed with `rows` or `time` methods --
see links to extension documentation below.

Minimum versions for supported databases:

- PostgreSQL 9.5
- Microsoft SQL Server 2005 -- only supports `system` (percent) and `rows`
(count)

References:

- http://www.neilconway.org/talks/hacking/ottawa/sql_standard.pdf
- https://wiki.postgresql.org/wiki/TABLESAMPLE_Implementation
- http://blog.2ndquadrant.com/tablesample-in-postgresql-9-5-2/
- http://www.depesz.com/2015/05/23/waiting-for-9-5-tablesample-sql-
standard-and-extensible/
- http://www.postgresql.org/docs/9.5/static/tsm-system-time.html
- http://www.postgresql.org/docs/9.5/static/tsm-system-rows.html
- https://msdn.microsoft.com/en-us/library/ms189108(v=sql.105).aspx

--
Ticket URL: <https://code.djangoproject.com/ticket/26506>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 15, 2016, 9:41:12 AM4/15/16
to django-...@googlegroups.com
#26506: Implement support for TABLESAMPLE
-------------------------------------+-------------------------------------

Reporter: pope1ni | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: tablesample | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Before doing any coding, please create a thread on the
DevelopersMailingList to get feedback on the proposed APIs and add a link
to it in this ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/26506#comment:1>

Django

unread,
May 5, 2016, 12:55:11 AM5/5/16
to django-...@googlegroups.com
#26506: Implement support for TABLESAMPLE
-------------------------------------+-------------------------------------

Reporter: pope1ni | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: tablesample | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by pembo13):

* cc: pembo13@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/26506#comment:2>

Reply all
Reply to author
Forward
0 new messages