简体   繁体   中英

Slow SQL inserts OracleDB/EDB

Here's the test scenario, I have multiple asynchronous requests in a JavaScript Application that:

  1. creates an object and saves it in the database.
  2. queries that object and make changes to it and saves it to the database (this step is done 2 or 3 times to add new items to the object)

steps 1 and 2 are repeated for every new object, for a long test scenario.

Upon investigation, it turns out some selects and inserts are taking up to 11 seconds, and more over time, which is probably expected when you are doing that many inserts for the same table, and each insert has to wait for the other one to be finished.

My question is, how to mitigate this issue or maybe even get rid of it without losing its asynchronous ability?

I know a multi-value insert is much faster than a single one, but how would you do such a thing in an asynchronous application?

you might want to refactor how you are doing things. instead of inserting one at a time post an array of objects to your backend and then insert them all at once. something like

https://livesql.oracle.com/apex/livesql/file/content_BM1LJQ87M5CNIOKPOWPV6ZGR3.html

INSERT INTO people (person_id, given_name, family_name, title) 
  WITH names AS ( 
    SELECT 4, 'Ruth',     'Fox',      'Mrs'    FROM dual UNION ALL 
    SELECT 5, 'Isabelle', 'Squirrel', 'Miss'   FROM dual UNION ALL 
    SELECT 6, 'Justin',   'Frog',     'Master' FROM dual UNION ALL 
    SELECT 7, 'Lisa',     'Owl',      'Dr'     FROM dual 
  ) 
  SELECT * FROM names

you might also want to look into the merge statement it can update and insert into a single table with one statement

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM