0


我有以下表格结构。

  reservation: (InnoDB)
  ------------------------------------------
  id INT,
  date DATE,
  item_id INT,
  slot VARCHAR(50);
  PRIMARY KEY(id), UNIQUE KEY(item_id,date).

现在我正在尝试在事务内的保留表上使用 SELECT.....FOR UPDATE 来锁定特定 item_id 的日期范围内的特定行(例如:2012-06-15 到 2012-06-16)。

SELECT availability FROM reservation WHERE item_id={$item_id} AND (date>='{$to_date}' AND date<='{$from_date}') FOR UPDATE

现在,当我使用上述语句时,它会阻止特定 item_id 的所有行,甚至超出日期范围。我也在使用这个唯一键(item_id,date)。

如何仅锁定特定 item_id 的特定日期范围?

问候,
拉维。

添加:

 |
=====================================
120615 20:14:13 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 24 seconds
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 12, signal count 12
Mutex spin waits 0, rounds 180, OS waits 4
RW-shared spins 10, OS waits 5; RW-excl spins 2, OS waits 2
------------
TRANSACTIONS
------------
Trx id counter 0 15147
Purge done for trx's n:o < 0 15136 undo n:o < 0 0
History list length 2
Total number of lock structs in row lock hash table 2
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, OS thread id 2940
MySQL thread id 76, query id 1487 localhost 127.0.0.1 root
SHOW innodb status
---TRANSACTION 0 15143, not started, OS thread id 2588
MySQL thread id 10, query id 578 localhost 127.0.0.1 root
---TRANSACTION 0 15144, ACTIVE 11526 sec, OS thread id 2740
3 lock struct(s), heap size 320
MySQL thread id 11, query id 577 localhost 127.0.0.1 root
--------
FILE I/O
--------
I/O thread 0 state: wait Windows aio (insert buffer thread)
I/O thread 1 state: wait Windows aio (log thread)
I/O thread 2 state: wait Windows aio (read thread)
I/O thread 3 state: wait Windows aio (write thread)
Pending normal aio reads: 0, aio writes: 0,
 ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
187 OS file reads, 75 OS file writes, 29 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2,
0 inserts, 0 merged recs, 0 merges
Hash table size 62383, used cells 0, node heap has 1 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 0 8287163
Log flushed up to   0 8287163
Last checkpoint at  0 8287163
0 pending log writes, 0 pending chkp writes
24 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 23277934; in additional pool allocated 1430400
Buffer pool size   960
Free buffers       895
Database pages     64
Modified db pages  0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 64, created 0, written 51
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread id 1544, state: waiting for server activity
Number of rows inserted 10, updated 0, deleted 0, read 66
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
 |
4

0 回答 0