Sql insert query performance

前端 未结 4 1317
忘掉有多难
忘掉有多难 2021-01-02 21:28

I want to insert n records into a single table. There may be many concurrent users and they may insert/update/select data from this table. What is better way to insert in a

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 22:07

    This totally depends on what RDBMS you are using.

    In Oracle, writes never block reads, that's why you can safely put your data all at once. Note, though, that this will degrade performance, since the concurrent queries will need to fetch the data out of UNDO tablespace that will require extra reads.

    In SQL Server writes do block reads on affected rows / pages / tables (depending on lock escalation issues), unless you set TRANSACTION ISOLATION LEVEL to SNAPSHOT.

    In all transactional engines that allow concurrent writing and reading, the engine needs to store both old and new data somewhere for it to be available at the same time.

    In Oracle, old data is copied into the UNDO tablespace.

    In SQL Server, it gets copied into tempdb (only when SNAPSHOT isolation is enabled, otherwise it's just locked).

    This always requires some resources (memory or disk), and you can run out of these resources if your UPDATE query affects lots of rows.

提交回复
热议问题