Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Xerox does it again and again and again and ...


devel / comp.databases.mysql / Re: Slow deletes (MariaDB)

SubjectAuthor
* Slow deletes (MariaDB)DFS
+* Re: Slow deletes (MariaDB)Jerry Stuckle
|`- Re: Slow deletes (MariaDB)DFS
+- Re: Slow deletes (MariaDB)Axel Schwenke
`* Re: Slow deletes (MariaDB)J.O. Aho
 `- Re: Slow deletes (MariaDB)DFS

1
Slow deletes (MariaDB)

<mIRTI.6222$VkD6.1837@fx01.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=37&group=comp.databases.mysql#37

  copy link   Newsgroups: comp.databases.mysql
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!peer01.ams4!peer.am4.highwinds-media.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx01.iad.POSTED!not-for-mail
From: nos...@dfs.com (DFS)
Subject: Slow deletes (MariaDB)
Newsgroups: comp.databases.mysql
X-Mozilla-News-Host: news://usnews.blocknews.net
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Lines: 21
Message-ID: <mIRTI.6222$VkD6.1837@fx01.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Fri, 20 Aug 2021 17:34:10 UTC
Organization: blocknews - www.blocknews.net
Date: Fri, 20 Aug 2021 13:34:10 -0400
X-Received-Bytes: 1083
 by: DFS - Fri, 20 Aug 2021 17:34 UTC

Deletes of this type are very slow:

delete from childtbl
where id1 in
( select id1
from parenttbl
where id2 in
(
select id2
from othertbl
where condition
)
)

Like 1.5 minutes to delete a couple thousand rows.

How can I speed them up?

Re: Slow deletes (MariaDB)

<sfoqkg$8eg$2@jstuckle.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=39&group=comp.databases.mysql#39

  copy link   Newsgroups: comp.databases.mysql
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!jstuckle.eternal-september.org!.POSTED!not-for-mail
From: jstuck...@attglobal.net (Jerry Stuckle)
Newsgroups: comp.databases.mysql
Subject: Re: Slow deletes (MariaDB)
Date: Fri, 20 Aug 2021 14:00:46 -0400
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <sfoqkg$8eg$2@jstuckle.eternal-september.org>
References: <mIRTI.6222$VkD6.1837@fx01.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 20 Aug 2021 18:00:49 -0000 (UTC)
Injection-Info: jstuckle.eternal-september.org; posting-host="81bb4d10e646f550df40771fda0b9ba2";
logging-data="8656"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/p87gYIUlQSkuw4PZ/6MzWB2vxAIIGPp0="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:GlW/mkj5Gu6558hiPzxVj0kq3ow=
In-Reply-To: <mIRTI.6222$VkD6.1837@fx01.iad>
Content-Language: en-US
 by: Jerry Stuckle - Fri, 20 Aug 2021 18:00 UTC

On 8/20/2021 1:34 PM, DFS wrote:
> Deletes of this type are very slow:
>
> delete from childtbl
> where id1 in
> (
>   select id1
>   from parenttbl
>   where id2 in
>   (
>    select id2
>    from othertbl
>    where condition
>   )
> )
>
>
> Like 1.5 minutes to delete a couple thousand rows.
>
> How can I speed them up?
>
>

How big are your tables? Do you have indexes on id1 and id2 in their
appropriate tables?

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

Re: Slow deletes (MariaDB)

<CZTTI.4242$kQ4.3415@fx13.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=40&group=comp.databases.mysql#40

  copy link   Newsgroups: comp.databases.mysql
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx13.iad.POSTED!not-for-mail
Subject: Re: Slow deletes (MariaDB)
Newsgroups: comp.databases.mysql
References: <mIRTI.6222$VkD6.1837@fx01.iad>
<sfoqkg$8eg$2@jstuckle.eternal-september.org>
From: nos...@dfs.com (DFS)
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <sfoqkg$8eg$2@jstuckle.eternal-september.org>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Lines: 54
Message-ID: <CZTTI.4242$kQ4.3415@fx13.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Fri, 20 Aug 2021 20:09:06 UTC
Organization: blocknews - www.blocknews.net
Date: Fri, 20 Aug 2021 16:09:06 -0400
X-Received-Bytes: 2110
 by: DFS - Fri, 20 Aug 2021 20:09 UTC

On 8/20/2021 2:00 PM, Jerry Stuckle wrote:
> On 8/20/2021 1:34 PM, DFS wrote:
>> Deletes of this type are very slow:
>>
>> delete from childtbl
>> where id1 in
>> (
>>    select id1
>>    from parenttbl
>>    where id2 in
>>    (
>>     select id2
>>     from othertbl
>>     where condition
>>    )
>> )
>>
>>
>> Like 1.5 minutes to delete a couple thousand rows.
>>
>> How can I speed them up?
>>
>>
>
> How big are your tables?

In this case:
parenttbl nearly 3M rows
childtbl nearly 3M rows
othertbl 130K rows

> Do you have indexes on id1 and id2 in their
> appropriate tables?

Yes.

MariaDB selects are fast, but a delete query as above required 1.25
minutes in MariaDB, but 0.3 seconds in SQLite (identical
SQL/tables/structures/indexes/starting rowcounts).

Depending on the table, select count(*) in MariaDB is also agonizingly
slow: eg 1.67 minutes vs 1 second in SQLite for a table of 3 int columns
(nearly 15M rows)

SQLite is no MariaDB, I understand that, but geez.

I researched the slow MariaDB DELETE and row counting, and there're no
easy answers.

https://www.google.com/search?q=mariadb+slow+delete

Apparently the same issues occur in PostgreSQL.

Re: Slow deletes (MariaDB)

<sfp6a0$ltl$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=41&group=comp.databases.mysql#41

  copy link   Newsgroups: comp.databases.mysql
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: axel.sch...@gmx.de (Axel Schwenke)
Newsgroups: comp.databases.mysql
Subject: Re: Slow deletes (MariaDB)
Date: Fri, 20 Aug 2021 23:20:00 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <sfp6a0$ltl$1@dont-email.me>
References: <mIRTI.6222$VkD6.1837@fx01.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 20 Aug 2021 21:20:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7319639a37025e9fdaca90dc77e0b33c";
logging-data="22453"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KfuRKhd4NYK0V3YCzBphz/fGKIHoQ/xI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.9.1
Cancel-Lock: sha1:EgHutZc6IQeSEI8QVuC5OUz7jn8=
In-Reply-To: <mIRTI.6222$VkD6.1837@fx01.iad>
Content-Language: en-US
 by: Axel Schwenke - Fri, 20 Aug 2021 21:20 UTC

On 20.08.2021 19:34, DFS wrote:

> delete from childtbl
> where id1 in
> (
>   select id1
>   from parenttbl
>   where id2 in
>   (
>    select id2
>    from othertbl
>    where condition
>   )
> )

> How can I speed them up?

Show the EXPLAIN for the query. Then we can talk.

https://mariadb.com/kb/en/explain/

Re: Slow deletes (MariaDB)

<ioan2iFjdecU1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=42&group=comp.databases.mysql#42

  copy link   Newsgroups: comp.databases.mysql
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: use...@example.net (J.O. Aho)
Newsgroups: comp.databases.mysql
Subject: Re: Slow deletes (MariaDB)
Date: Sat, 21 Aug 2021 00:01:54 +0200
Lines: 52
Message-ID: <ioan2iFjdecU1@mid.individual.net>
References: <mIRTI.6222$VkD6.1837@fx01.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net T9xLICYKpS57sxX35GSjiQSr4KgmxzU5JSvVAqeYzXiDvfTo3g
Cancel-Lock: sha1:VWE1kWJzhtCCks70vhh1supp35E=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <mIRTI.6222$VkD6.1837@fx01.iad>
Content-Language: en-US-large
 by: J.O. Aho - Fri, 20 Aug 2021 22:01 UTC

On 20/08/2021 19.34, DFS wrote:
> Deletes of this type are very slow:
>
> delete from childtbl
> where id1 in
> (
>   select id1
>   from parenttbl
>   where id2 in
>   (
>    select id2
>    from othertbl
>    where condition
>   )
> )
>
>
> Like 1.5 minutes to delete a couple thousand rows.
>
> How can I speed them up?

Why not join the tables

DELETE childtbl
FROM childtbl
INNER JOIN parenttbl ON parenttbl.id1 =

childtbl.id1
INNER JOIN othertbl.id2 ON parenttbl.id2
WHERE othertbl[condition]

even

DELETE FROM childtbl
WHERE id1 IN(
SELECT id1 FROM parenttbl
INNER JOIN othertbl ON othertbl.id2 = parenttbl.id2
WHERE othertbl[condition]
)

could be faster than the original.

Sure you should compare the explain result that others have already
pointed out.

--

//Aho

Re: Slow deletes (MariaDB)

<oX_TI.7796$892.4789@fx19.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=44&group=comp.databases.mysql#44

  copy link   Newsgroups: comp.databases.mysql
Path: i2pn2.org!i2pn.org!news.uzoreto.com!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!nntp.speedium.network!feeder01!81.171.65.13.MISMATCH!peer01.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx19.iad.POSTED!not-for-mail
Subject: Re: Slow deletes (MariaDB)
Newsgroups: comp.databases.mysql
References: <mIRTI.6222$VkD6.1837@fx01.iad> <ioan2iFjdecU1@mid.individual.net>
From: nos...@dfs.com (DFS)
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <ioan2iFjdecU1@mid.individual.net>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Lines: 84
Message-ID: <oX_TI.7796$892.4789@fx19.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Sat, 21 Aug 2021 04:04:36 UTC
Organization: blocknews - www.blocknews.net
Date: Sat, 21 Aug 2021 00:04:35 -0400
X-Received-Bytes: 2341
 by: DFS - Sat, 21 Aug 2021 04:04 UTC

On 8/20/2021 6:01 PM, J.O. Aho wrote:
> On 20/08/2021 19.34, DFS wrote:
>> Deletes of this type are very slow:
>>
>> delete from childtbl
>> where id1 in
>> (
>>    select id1
>>    from parenttbl
>>    where id2 in
>>    (
>>     select id2
>>     from othertbl
>>     where condition
>>    )
>> )
>>
>>
>> Like 1.5 minutes to delete a couple thousand rows.
>>
>> How can I speed them up?
>
> Why not join the tables
>
> DELETE childtbl
> FROM childtbl
> INNER JOIN parenttbl ON parenttbl.id1 =
>
> childtbl.id1
> INNER JOIN othertbl.id2 ON parenttbl.id2
> WHERE othertbl[condition]
>
>
> even
>
> DELETE FROM childtbl
> WHERE id1 IN(
>     SELECT id1 FROM parenttbl
>     INNER JOIN othertbl ON othertbl.id2 = parenttbl.id2
>     WHERE othertbl[condition]
> )

> could be faster than the original.

I've gotten gotten used to using the original syntax in SQLite for the
past N years, and it's always fast.

original syntax in MariaDB:

delete from child
where id1 in
( select id1
from parent
where id2 in
(
select id2
from other
where condition
)
) Query OK, 2557 rows affected (49.864 sec)

orig syntax is about 4 seconds in SQLite.

new syntax in MariaDB:

delete c.*
from child c, parent p, other o
where c.id = p.id
and p.id2 = o.id2
and o.condition
Query OK, 2557 rows affected (0.489 sec)

new syntax won't execute in SQLite.

Thanks!

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor