Query execution was interrupted, error #1317

后端 未结 3 1598
猫巷女王i
猫巷女王i 2020-12-16 15:40

What I have is a table with a bunch of products (books, in this case). My point-of-sale system generates me a report that has the ISBN (unique product number) and perpetual

相关标签:
3条回答
  • 2020-12-16 16:20

    try to use INNER JOIN in the two tables like that

           UPDATE `inventory` 
           INNER JOIN `sales` 
           ON  `inventory`.`isbn` = `sales`.`isbn`
           SET `inventory`.`numbersold` = `sales`.`numbersold` 
    
    0 讨论(0)
  • 2020-12-16 16:36

    UPDATE inventory,sales SET inventory.numbersold = sales.numbersold WHERE inventory.isbn = sales.isbn AND inventory.id < 5000

    UPDATE inventory,sales SET inventory.numbersold = sales.numbersold WHERE inventory.isbn = sales.isbn AND inventory.id > 5000 inventory.id < 10000

    ...

    If the error, you can try to reduce the number to 1000, for example

    0 讨论(0)
  • 2020-12-16 16:41

    I've probably come to this a bit late, but... It certainly looks like the query is being interrupted by an execution time limit. There may be no easy way around this, but here's a couple of ideas:

    Make sure that inventory.isbn and sales.isbn are indexed. If they aren't, adding an index will reduce your execution time dramatically.

    if that doesn't work, break the query down into blocks and run it several times:

    UPDATE `inventory`,`sales` 
      SET `inventory`.`numbersold` = `sales`.`numbersold` 
    WHERE `inventory`.`isbn` = `sales`.`isbn`
      AND substring(`inventory`.sales`,1,1) = '1';
    

    The AND clause restricts the search to ISBNs starting with the digit 1. Run the query for each digit from '0' to '9'. For ISBNs you might find selecting on the last character gives better results. Use substring(inventory.sales,-1)`

    0 讨论(0)
提交回复
热议问题