How can I make this more efficient?
I have this code snippet that finds matching records based on composite key string and it is very slow. Is there a better way to do this?
Main method:
toString:
Query:
24 Replies
ā
This post has been reserved for your question.
Hey @Kale Vivi! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
how long does sql query take in sql client?
@Kale Vivi
Like only if i directly call the sql ?
I don't know because I need to do this 500K records
in batches of 1000
is it a requirement that its a batch of 1k
what if you try less or more
I can try but I think there might be jpa or postgres db limits here?
(at least for the more case)
Why would less be faster?
na
no clue just try it l0l
maybe its gonna help
I would think it's slower?
are you doing the thing that you asked before btw
checking if exists and deleting
this ones faster
than updating
ig
Well I mean this is one of the bottlenecks, so tackling this approach first
or
you could update do the update query
I need to do this first before the update, this is just hte find that is taking forever
update where bla bla bla bla
and if it updates nothing so its 0 then you just save
so you technically dont even have to find
š±
don't I need to pull the records to update them?
I'm confused
i mean
you can
but you can also just use the query
if you do a whole resource update
you technically wont even have to pull the entity from db
but then you wont have locking so thats the con
if you wanted to add it
I mean I can't just update because I first need to know if it's an update or insert case
so that's where this lookup is required first
if I jsut do update for everything, I will get fails for insert cases right?
where those records don't exist
you can call the update and if record doesnt exist it wont update and you will get 0 as the response
0 rows changed
and if its 0 then you call insert
so worst case scenario its two queries
How do I get this response?
from the update method
Can you share an example of the update method?
ok
gpt btw
not me
removed the transactional
wasnt needed
That doesn't help me because it just returns the number updated or not and not which ones
How do I which ones to insert then?
well you would need to call the update as a separate query with each entity
additionally you could just delete all by the ids you have
and then insert them
but im not sure about the times
and efficiency
š¤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.