Почему SQL Server 2008 блокирует ВЫБОР на длинной ВСТАВКЕ транзакции?

В вашем user.route.js вам необходимо экспортировать что-то вроде этого:

module.exports = function (variable) {
    return (req, res, next) => {
        // your middleware
        next()
    }
}

Или с карри ( https://wsvincent.com/javascript-curry/ ):

module.exports = variable => (req, res, next) => {
   const myUsedVariable = variable + 1
   res.send(myUsedVariable)
}

И если вы используете экспресс. Маршрутизатор:

var express = require('express')
var router = express.Router()

router.get('/', function(req, res) {
  res.send('Birds home page')
})

module.exports = variable => {
   // do something with your variable
   router.use(function displayVariable(req, res, next) {
      console.log(variable)
      next()
   })

   return router
}

17
задан stevemac 27 April 2009 в 06:07
поделиться

3 ответа

это поведение блокировки является функцией SQL Server. Начиная с 2005 года, вы можете использовать управления версиями на уровне строк (что по умолчанию используется в Oracle), чтобы достичь того же результата и не блокировать ваш выбор. Это создает дополнительную нагрузку на базу данных tempdb, поскольку база данных tempdb поддерживает управление версиями на уровне строк, поэтому убедитесь, что вы согласны с этим. Чтобы заставить SQL вести себя так, как вы хотите, запустите:

ALTER DATABASE MyDatabase
SET ALLOW_SNAPSHOT_ISOLATION ON

ALTER DATABASE MyDatabase
SET READ_COMMITTED_SNAPSHOT ON
12
ответ дан 30 November 2019 в 14:01
поделиться

This is completely standard behaviour in SQL Server and Sybase (at least).

Data changes (Insert, update, delete) require exclusive locks. this causes readers to be blocked:

With an exclusive (X) lock, no other transactions can modify data; read operations can take place only with the use of the NOLOCK hint or read uncommitted isolation level.

With SQL Server 2005 and above, they introduced snapshot isolation (aka row versioning). From MS BOL: Understanding Row Versioning-Based Isolation Levels. This means a reader has latest committed data but if you then want to write back, say, then you may find the data is wrong because it changed in the blocking transaction.

Now, this is why best practice is to keep transactions short. For example, only process what you need to between BEGIN/COMMIT, don't send emails from triggers etc.

Edit:

Locking like this happens all the time in SQL Server. However, locking for too long becomes blocking that reduce performance. Too long is subjective, obviously.

4
ответ дан 30 November 2019 в 14:01
поделиться

This exists in MySQL too. Here's the logic behind it: if you perform a SELECT on some data, you expect it to operate on an up-to-date dataset. That's why INSERT results in a table-level lock (that is unless the engine is able to perform row-level locking, like innodb can). There are ways to disable this behaviour, so that you can do "dirty reads", but they all are software (or even database-engine) specific.

1
ответ дан 30 November 2019 в 14:01
поделиться
Другие вопросы по тегам:

Похожие вопросы: