Discussion:
Batch deletes
christofear
2013-07-24 13:41:11 UTC
Permalink
Can someone help me with this?

When using where queries for batch deletes, the domain instances are
being deleted immediately(like delete(flush: true) ) or not? For example:

Person.findAllByFirstName("George")*.delete(flush: true)

is equal to

Person.where {
firstName == 'George'
}.deleteAll()

or not?

Please help!


Thnx



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Sudhir N
2013-07-24 14:20:24 UTC
Permalink
You can turn sql logging on for Hibernate and see what queries are being
fired for both cases.

logSql = true in DataSource.groovy


Sudhir N
[Independent Grails/Java developer]

-----Original Message-----
From: christofear [mailto:***@gmail.com]
Sent: Wednesday, July 24, 2013 7:11 PM
To: ***@grails.codehaus.org
Subject: [grails-user] Batch deletes

Can someone help me with this?

When using where queries for batch deletes, the domain instances are being
deleted immediately(like delete(flush: true) ) or not? For example:

Person.findAllByFirstName("George")*.delete(flush: true)

is equal to

Person.where {
firstName == 'George'
}.deleteAll()

or not?

Please help!


Thnx



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Sergio Michels
2013-07-24 14:27:12 UTC
Permalink
Delete have the flush option, so my guess is that it works like save:
http://grails.org/doc/latest/ref/Domain%20Classes/delete.html

How about:

Person.where {
firstName == 'George'
}*.delete(flush:true)


--
Sérgio Michels
Post by Sudhir N
You can turn sql logging on for Hibernate and see what queries are being
fired for both cases.
logSql = true in DataSource.groovy
Sudhir N
[Independent Grails/Java developer]
-----Original Message-----
Sent: Wednesday, July 24, 2013 7:11 PM
Subject: [grails-user] Batch deletes
Can someone help me with this?
When using where queries for batch deletes, the domain instances are being
Person.findAllByFirstName("George")*.delete(flush: true)
is equal to
Person.where {
firstName == 'George'
}.deleteAll()
or not?
Please help!
Thnx
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
christofear
2013-07-24 14:39:44 UTC
Permalink
Well I use the MongoDB Gorm plugin(Hibernate has been uninstalled). I
just want to know if the actual delete occurs immediately, when using
deleteAll() method on where queries. I also don't want to use
*.delete(flush: true) for optimization purposes. I just want to
immediately batch delete with a single query, not separately one by one
the instances like *.delete(flush: true)
Post by Sergio Michels
http://grails.org/doc/latest/ref/Domain%20Classes/delete.html
Person.where {
firstName == 'George'
}*.delete(flush:true)
--
Sérgio Michels
You can turn sql logging on for Hibernate and see what queries are being
fired for both cases.
logSql = true in DataSource.groovy
Sudhir N
[Independent Grails/Java developer]
-----Original Message-----
Sent: Wednesday, July 24, 2013 7:11 PM
Subject: [grails-user] Batch deletes
Can someone help me with this?
When using where queries for batch deletes, the domain instances are being
Person.findAllByFirstName("George")*.delete(flush: true)
is equal to
Person.where {
firstName == 'George'
}.deleteAll()
or not?
Please help!
Thnx
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Sebastian Gozin
2013-07-24 14:40:41 UTC
Permalink
Why don't you just try it and observe?
Offhand I'd expect batch updates to follow transaction write behind rules so they would not be flushed before the transaction is committed.
Post by christofear
Can someone help me with this?
Person.findAllByFirstName("George")*.delete(flush: true)
is equal to
Person.where {
firstName == 'George'
}.deleteAll()
or not?
Please help!
Thnx
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Aaron Long
2013-07-24 21:05:14 UTC
Permalink
Those are not equal. The first will do one delete per record found and
flush immediately after each one. The second is much more efficient
and will do a single delete with a where clause. If you have
beforeDelete events on objects, the second version may not fire them
(I can't recall but I believe that is the case).

-Aaron
Post by Sebastian Gozin
Why don't you just try it and observe?
Offhand I'd expect batch updates to follow transaction write behind rules so they would not be flushed before the transaction is committed.
Post by christofear
Can someone help me with this?
Person.findAllByFirstName("George")*.delete(flush: true)
is equal to
Person.where {
firstName == 'George'
}.deleteAll()
or not?
Please help!
Thnx
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
christofear
2013-07-24 23:05:08 UTC
Permalink
I do have a beforeDelete event! But I want to know if the second
version(deleteAll()) flushes immediately.
Post by Aaron Long
Those are not equal. The first will do one delete per record found and
flush immediately after each one. The second is much more efficient
and will do a single delete with a where clause. If you have
beforeDelete events on objects, the second version may not fire them
(I can't recall but I believe that is the case).
-Aaron
Post by Sebastian Gozin
Why don't you just try it and observe?
Offhand I'd expect batch updates to follow transaction write behind rules so they would not be flushed before the transaction is committed.
Post by christofear
Can someone help me with this?
Person.findAllByFirstName("George")*.delete(flush: true)
is equal to
Person.where {
firstName == 'George'
}.deleteAll()
or not?
Please help!
Thnx
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Aaron Long
2013-07-25 03:23:43 UTC
Permalink
The deleteAll doesn't operate on objects in the session but rather it
executes a delete directly against the database. I don't really think
flushing is relevant in that case. You should see that it executes
immediately. If you have a beforeDelete() hook, you shouldn't use it as the
hook will not be executed since the object is not instantiated and loaded
into the session before deleting.

-Aaron
Post by christofear
I do have a beforeDelete event! But I want to know if the second
version(deleteAll()) flushes immediately.
Post by Aaron Long
Those are not equal. The first will do one delete per record found and
flush immediately after each one. The second is much more efficient
and will do a single delete with a where clause. If you have
beforeDelete events on objects, the second version may not fire them
(I can't recall but I believe that is the case).
-Aaron
Why don't you just try it and observe?
Post by Sebastian Gozin
Offhand I'd expect batch updates to follow transaction write behind
rules so they would not be flushed before the transaction is committed.
Can someone help me with this?
Post by christofear
When using where queries for batch deletes, the domain instances are
Person.findAllByFirstName("**George")*.delete(flush: true)
is equal to
Person.where {
firstName == 'George'
}.deleteAll()
or not?
Please help!
Thnx
------------------------------**------------------------------**
---------
http://xircles.codehaus.org/**manage_email<http://xircles.codehaus.org/manage_email>
------------------------------**------------------------------**
---------
http://xircles.codehaus.org/**manage_email<http://xircles.codehaus.org/manage_email>
------------------------------**------------------------------**
---------
http://xircles.codehaus.org/**manage_email<http://xircles.codehaus.org/manage_email>
------------------------------**------------------------------**---------
http://xircles.codehaus.org/**manage_email<http://xircles.codehaus.org/manage_email>
christofear
2013-07-25 17:32:25 UTC
Permalink
Yeap that's true about the beforeDelete hook! But I am considering
replacing Burt's solution on many-to-many(e.g UserRole) classes:

static void removeAll(User user) {
UserRole.findAllByUser(user)*.delete(flush: true)
}

with

static void removeAll(User u) {
UserRole.where { user == u }.deleteAll()
}
Post by Aaron Long
The deleteAll doesn't operate on objects in the session but rather it
executes a delete directly against the database. I don't really think
flushing is relevant in that case. You should see that it executes
immediately. If you have a beforeDelete() hook, you shouldn't use it
as the hook will not be executed since the object is not instantiated
and loaded into the session before deleting.
-Aaron
I do have a beforeDelete event! But I want to know if the second
version(deleteAll()) flushes immediately.
Those are not equal. The first will do one delete per record found and
flush immediately after each one. The second is much more efficient
and will do a single delete with a where clause. If you have
beforeDelete events on objects, the second version may not fire them
(I can't recall but I believe that is the case).
-Aaron
On Jul 24, 2013, at 9:44 AM, Sebastian Gozin
Why don't you just try it and observe?
Offhand I'd expect batch updates to follow transaction
write behind rules so they would not be flushed before the
transaction is committed.
On 24 Jul 2013, at 15:41, christofear
Can someone help me with this?
When using where queries for batch deletes, the domain
instances are being deleted immediately(like
Person.findAllByFirstName("George")*.delete(flush: true)
is equal to
Person.where {
firstName == 'George'
}.deleteAll()
or not?
Please help!
Thnx
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
buffonomics
2014-05-18 18:36:56 UTC
Permalink
I wrote about this Here
<http://deveki.com/softdev/gorm-bulk-delete-already/> .



--
View this message in context: http://grails.1312388.n4.nabble.com/Batch-deletes-tp4647149p4656924.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Continue reading on narkive:
Loading...