When will the INSERT happen .. ON DUPLICATE?

I was looking for instructions INSERT... ON DUPLICATE KEYdue to a constraint error, but I irreversibly edited this line and I no longer get the error. I'm sure I edited either request_path, or target_path. Some of the values ​​that have already been specified for a specific area:

store_id |   id_path    | is_system
   6     | category/494 |     1

The request was

INSERT INTO `core_url_rewrite` (`store_id`,`category_id`,`product_id`,`id_path`,`request_path`,`target_path`,`is_system`) 
VALUES (6, 494, NULL, 'category/494', 'lessons/teacher-s-planning-calendar/n-a', 'catalog/category/view/id/494', 1) 
ON DUPLICATE KEY UPDATE 
    `store_id` = VALUES(`store_id`),
    `category_id` = VALUES(`category_id`), 
    `product_id` = VALUES(`product_id`), 
    `id_path` = VALUES(`id_path`), 
    `request_path` = VALUES(`request_path`), 
    `target_path` = VALUES(`target_path`), 
    `is_system` = VALUES(`is_system`)

The error was

Integrity constraint violation: 1062 Duplicate entry 'category/494-1-6' 
for key 'UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID' 

There are two unique keys in this table.

UNIQUE KEY `UNQ_CORE_URL_REWRITE_REQUEST_PATH_STORE_ID` (`request_path`,`store_id`),
UNIQUE KEY `UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID` (`id_path`,`is_system`,`store_id`)

I no longer get this restriction error after accidentally changing some values ​​in a string. What will cause my request to cause this restriction error?

+4
source share
3 answers

, ( ) .

, , :

(6, 494, NULL, 'category/123', 'lessons/teacher-s-planning-calendar/n-a', 'catalog/category/view/id/123', 1),
(6, 494, NULL, 'category/494', 'lessons/foobar/whatever', 'catalog/category/view/id/494', 1);

:

(6, 494, NULL, 'category/494', 'lessons/teacher-s-planning-calendar/n-a', 'catalog/category/view/id/494', 1)

( request_path = 'lessons/teacher-s-planning-calendar/n-a' store_id = 6 ), ON DUPLICATE KEY UPDATE , . , , id_path = 'category/494', is_system = 1 store_id = 6.

SQLize, .


, , INSERT ON DUPLICATE KEY UPDATE , MySQL . , , , , .

:

, ON DUPLICATE KEY UPDATE .

+3

: , ?

INSERT (request_path,store_id). MySQL, MySQL ,

UPDATE core_url_rewrite
   SET store_id     = ?
     , category_id  = ?
     , product_id   = ?
     , id_path      = ?
     , request_path = ?
     , target_path  = ?
     , is_system    = ?
 WHERE ( request_path = ? AND store_id = ? )
    OR ( id_path = ? AND id_system = ? AND store_id = ?)
 LIMIT 1

update id_path id_system ( ) 'category/494' '1', .

" " UPDATE. , INSERT.


:

'category/494-1-6'

, , .

. , , ; .

, , .


INSERT " ", . MySQL UPDATE. UPDATE.

+2

, , , Google, .

, url_rewrite_id max unsigned int size 4 294 967 295

- , .

$adapter->insertOnDuplicate($this->getMainTable(), $rewriteData);

It seems that INSERT ... ON DUPLICATE UPDATE (used by the Magento index) indexes this index every time the indexer starts.

0
source

All Articles