Обсуждение: Enhancement Request

Поиск
Список
Период
Сортировка

Enhancement Request

От
"Campbell, Lance"
Дата:

It would be nice if the DELETE FROM supported LIMIT. I can already feel the dislike for this post coming back in my direction.

 

I have had numerous times over the years where I need to delete a lot of rows from a table but because each row is linked to so many other tables it will cause a problem in performance if I don’t limit the size of the deletion.

 

Just throwing this out there.

 

Thanks,

 

Lance

Re: Enhancement Request

От
MichaelDBA
Дата:
Cheat a bit....
Use a CTE with a limit on the select and then delete everything from the CTE.


Campbell, Lance wrote on 1/31/2024 2:29 PM:

It would be nice if the DELETE FROM supported LIMIT. I can already feel the dislike for this post coming back in my direction.

 

I have had numerous times over the years where I need to delete a lot of rows from a table but because each row is linked to so many other tables it will cause a problem in performance if I don’t limit the size of the deletion.

 

Just throwing this out there.

 

Thanks,

 

Lance



Regards,

Michael Vitale

Michaeldba@sqlexec.com

703-600-9343 


Вложения

Re: Enhancement Request

От
Alex Balashov
Дата:
> On 31 Jan 2024, at 14:32, MichaelDBA <MichaelDBA@sqlexec.com> wrote:
>
> Cheat a bit....
> Use a CTE with a limit on the select and then delete everything from the CTE.

Whoa! Thank you for that idea. That's thinking with portals.

--
Alex Balashov
Principal Consultant
Evariste Systems LLC
Web: https://evaristesys.com
Tel: +1-706-510-6800




RE: Enhancement Request

От
"Hajek, Nick"
Дата:

// It would be nice if the DELETE FROM supported LIMIT. I can already feel the dislike for this post coming back in my direction.

 

// I have had numerous times over the years where I need to delete a lot of rows from a table but because each row is linked to so many other tables it will cause // a problem in performance if I don’t limit the size of the deletion.

 

I use a query like this to accomplish a limited deletion –

 

Delete from table1 where table1.id in (select table1.id from table1 limit yourlimitnumber)

 

Re: Enhancement Request

От
M Sarwar
Дата:
Nick,
Are you confirming that DELETE FROM - LIMIT is working?
Thanks,
Sarwar


From: Hajek, Nick <Nick.Hajek@vishay.com>
Sent: Wednesday, January 31, 2024 2:34 PM
To: Campbell, Lance <lance@illinois.edu>; pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: RE: Enhancement Request
 

// It would be nice if the DELETE FROM supported LIMIT. I can already feel the dislike for this post coming back in my direction.

 

// I have had numerous times over the years where I need to delete a lot of rows from a table but because each row is linked to so many other tables it will cause // a problem in performance if I don’t limit the size of the deletion.

 

I use a query like this to accomplish a limited deletion –

 

Delete from table1 where table1.id in (select table1.id from table1 limit yourlimitnumber)

 

RE: Enhancement Request

От
"Campbell, Lance"
Дата:

No. I was submitting a request that we could add LIMIT to DELETE FROM. There are work arounds for this. But it would be nice to skip the work arounds.

 

From: M Sarwar <sarwarmd02@outlook.com>
Sent: Wednesday, January 31, 2024 2:47 PM
To: Hajek, Nick <Nick.Hajek@vishay.com>; Campbell, Lance <lance@illinois.edu>; pgsql-admin@postgresql.org
Subject: Re: Enhancement Request

 

Nick,

Are you confirming that DELETE FROM - LIMIT is working?

Thanks,

Sarwar

 


From: Hajek, Nick <Nick.Hajek@vishay.com>
Sent: Wednesday, January 31, 2024 2:34 PM
To: Campbell, Lance <lance@illinois.edu>; pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: RE: Enhancement Request

 

// It would be nice if the DELETE FROM supported LIMIT. I can already feel the dislike for this post coming back in my direction.

 

// I have had numerous times over the years where I need to delete a lot of rows from a table but because each row is linked to so many other tables it will cause // a problem in performance if I don’t limit the size of the deletion.

 

I use a query like this to accomplish a limited deletion –

 

Delete from table1 where table1.id in (select table1.id from table1 limit yourlimitnumber)

 

RE: Enhancement Request

От
"Hajek, Nick"
Дата:

 

 

[ External Email ]

// Are you confirming that DELETE FROM - LIMIT is working?

 

No, I don’t believe you can use limit in the delete itself but you can use it in a subselect and accomplish the same thing as shown in the example below.

 

 

// It would be nice if the DELETE FROM supported LIMIT. I can already feel the dislike for this post coming back in my direction.

 

// I have had numerous times over the years where I need to delete a lot of rows from a table but because each row is linked to so many other tables it will cause // a problem in performance if I don’t limit the size of the deletion.

 

I use a query like this to accomplish a limited deletion –

 

Delete from table1 where table1.id in (select table1.id from table1 limit yourlimitnumber)

 

Re: Enhancement Request

От
M Sarwar
Дата:
If they allow DELETE FROM-LIMT to work, it is going to harm  the general interest of the database.
In my opinion, that should not be implemented.
Thanks,
Sarwar


From: Hajek, Nick <Nick.Hajek@vishay.com>
Sent: Wednesday, January 31, 2024 3:50 PM
To: M Sarwar <sarwarmd02@outlook.com>; Campbell, Lance <lance@illinois.edu>; pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: RE: Enhancement Request
 

 

 

[ External Email ]

// Are you confirming that DELETE FROM - LIMIT is working?

 

No, I don’t believe you can use limit in the delete itself but you can use it in a subselect and accomplish the same thing as shown in the example below.

 

 

// It would be nice if the DELETE FROM supported LIMIT. I can already feel the dislike for this post coming back in my direction.

 

// I have had numerous times over the years where I need to delete a lot of rows from a table but because each row is linked to so many other tables it will cause // a problem in performance if I don’t limit the size of the deletion.

 

I use a query like this to accomplish a limited deletion –

 

Delete from table1 where table1.id in (select table1.id from table1 limit yourlimitnumber)

 

Re: Enhancement Request

От
Ron Johnson
Дата:
On Wed, Jan 31, 2024 at 3:55 PM M Sarwar <sarwarmd02@outlook.com> wrote:
If they allow DELETE FROM-LIMT to work, it is going to harm  the general interest of the database.
In my opinion, that should not be implemented.

Why would it harm the general interest of the database? 

What even does "the general interest of the database" mean?

Re: Enhancement Request

От
Ron Johnson
Дата:
On Wed, Jan 31, 2024 at 3:51 PM Hajek, Nick <Nick.Hajek@vishay.com> wrote: 
 [snip]

 Delete from table1 where table1.id in (select table1.id from table1 limit yourlimitnumber)


The IN predicate is only efficient for a very small number of elements, supported by an index.  People (including me) who would find DELETE FROM .. LIMIT TO ... useful want to delete a *lot* of rows (but not all in one giant statement).

Re: Enhancement Request

От
M Sarwar
Дата:
Hi Ron,

I appreciate asking this question.   For me, it is a complex question and it is an evolving idea.

When we use LIMIT clause in the SQL, SQL may be used in with / without ORDER of ASC / DESC,  UUID, Pseudo columns, ROWNUM, etc clauses.  When we use ORDER by,  LIMIT may be ok to DELETE but in the ROWNUM, other pseudo columns presence impact is hard to foresee.

In the DELETE statement, there may be WHERE conditions.  It is likely to complicate. If it is a simple DELETE statement with just LIMIT clause, it is hard to foresee and likely to complicate. Without a ORDER BY clause in the SQL, LIMIT will complicate the scenario.

 You may collect the opinion from few others and make a decision on this.

Thanks,
Sarwar



From: Ron Johnson <ronljohnsonjr@gmail.com>
Sent: Wednesday, January 31, 2024 8:31 PM
To: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: Enhancement Request
 
On Wed, Jan 31, 2024 at 3:55 PM M Sarwar <sarwarmd02@outlook.com> wrote:
If they allow DELETE FROM-LIMT to work, it is going to harm  the general interest of the database.
In my opinion, that should not be implemented.

Why would it harm the general interest of the database? 

What even does "the general interest of the database" mean?

Re: Enhancement Request

От
"David G. Johnston"
Дата:
On Thursday, February 1, 2024, M Sarwar <sarwarmd02@outlook.com> wrote:
 You may collect the opinion from few others and make a decision on this.

This feature has earned a place on the “not worth doing” page so a decision has been made.


David J.

Re: Enhancement Request

От
Olivier Gautherot
Дата:


El jue, 1 feb 2024 2:35, Ron Johnson <ronljohnsonjr@gmail.com> escribió:
On Wed, Jan 31, 2024 at 3:51 PM Hajek, Nick <Nick.Hajek@vishay.com> wrote: 
 [snip]

 Delete from table1 where table1.id in (select table1.id from table1 limit yourlimitnumber)


The IN predicate is only efficient for a very small number of elements, supported by an index.  People (including me) who would find DELETE FROM .. LIMIT TO ... useful want to delete a *lot* of rows (but not all in one giant statement).

Deleting large numbers of rows is a complex task with a lot of hidden issues (index management between other things). Adding a LIMIT paradigm will not simplify it in any way. I remember doing it on tables with over 50 millions rows and had my share of disaster recoveries. Partitions saved my life.

Cheers
Olivier

Re: Enhancement Request

От
Ron Johnson
Дата:
On Fri, Feb 2, 2024 at 3:50 AM Olivier Gautherot <ogautherot@gautherot.net> wrote:


El jue, 1 feb 2024 2:35, Ron Johnson <ronljohnsonjr@gmail.com> escribió:
On Wed, Jan 31, 2024 at 3:51 PM Hajek, Nick <Nick.Hajek@vishay.com> wrote: 
 [snip]

 Delete from table1 where table1.id in (select table1.id from table1 limit yourlimitnumber)


The IN predicate is only efficient for a very small number of elements, supported by an index.  People (including me) who would find DELETE FROM .. LIMIT TO ... useful want to delete a *lot* of rows (but not all in one giant statement).

Deleting large numbers of rows is a complex task with a lot of hidden issues (index management between other things). Adding a LIMIT paradigm will not simplify it in any way.

Smaller "bites" are easier to manage than giant bites.
 
I remember doing it on tables with over 50 millions rows and had my share of disaster recoveries. Partitions saved my life.

You must have been doing something wrong.

Re: Enhancement Request

От
M Sarwar
Дата:
Link is not only suggesting not to do DELETE - LIMIT but it is also suggesting to not to do UPDATE-LIMIT. 
Thanks,
Sarwar


From: David G. Johnston <david.g.johnston@gmail.com>
Sent: Thursday, February 1, 2024 9:15 PM
To: M Sarwar <sarwarmd02@outlook.com>
Cc: Ron Johnson <ronljohnsonjr@gmail.com>; pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: Enhancement Request
 
On Thursday, February 1, 2024, M Sarwar <sarwarmd02@outlook.com> wrote:
 You may collect the opinion from few others and make a decision on this.

This feature has earned a place on the “not worth doing” page so a decision has been made.


David J.

Re: Enhancement Request

От
Olivier Gautherot
Дата:


El vie, 2 feb 2024 14:54, Ron Johnson <ronljohnsonjr@gmail.com> escribió:
On Fri, Feb 2, 2024 at 3:50 AM Olivier Gautherot <ogautherot@gautherot.net> wrote:


El jue, 1 feb 2024 2:35, Ron Johnson <ronljohnsonjr@gmail.com> escribió:

...

Deleting large numbers of rows is a complex task with a lot of hidden issues (index management between other things). Adding a LIMIT paradigm will not simplify it in any way.

Smaller "bites" are easier to manage than giant bites.

To some extent, yes. But when it comes to large quantities overall, you have to consider vacuum, and it's best to take the DB offline for that. It depends on your use case.

 
I remember doing it on tables with over 50 millions rows and had my share of disaster recoveries. Partitions saved my life.

You must have been doing something wrong.

The mistake was to hope for the best and it didn't happen: we didn't take the feeding process offline (over 1000 rows per minute) and, after 24 hour, the DB was still trying to recover. We finally took everything offline for 2 hours and it stabilized. The delete process involved chunks of 15 million rows at a time, worth 1 month of data - not a minor issue.

Re: Enhancement Request

От
Ron Johnson
Дата:
On Fri, Feb 2, 2024 at 10:02 AM Olivier Gautherot <ogautherot@gautherot.net> wrote:


El vie, 2 feb 2024 14:54, Ron Johnson <ronljohnsonjr@gmail.com> escribió:
On Fri, Feb 2, 2024 at 3:50 AM Olivier Gautherot <ogautherot@gautherot.net> wrote:


El jue, 1 feb 2024 2:35, Ron Johnson <ronljohnsonjr@gmail.com> escribió:

...

Deleting large numbers of rows is a complex task with a lot of hidden issues (index management between other things). Adding a LIMIT paradigm will not simplify it in any way.

Smaller "bites" are easier to manage than giant bites.

To some extent, yes. But when it comes to large quantities overall, you have to consider vacuum,

I set autovacuum=off on the relevant table before purging, then vacuum-analyze before re-enabling autovacuum.
 
and it's best to take the DB offline for that. It depends on your use case.

The objections seem to presume that DBAs are incompetent, don't test ahead of time, and can't learn from their mistakes.