programing

고유 키가 정의된 mariadb 테이블의 이상한 동작(즉, 고유하지 않음)

codeshow 2023. 8. 30. 22:17
반응형

고유 키가 정의된 mariadb 테이블의 이상한 동작(즉, 고유하지 않음)

한 시스템에서 다른 시스템으로 BD를 내보내거나 가져오려고 하지만 가져오기가 실패하고 다음 오류가 발생합니다.

ERROR 1062 (23000) at line 8232: Duplicate entry '0-3-30168717-com_liferay_product_navigation_product_menu_web_...' for key 'IX_C7057FF7'

이 테이블은 다음과 같이 정의됩니다.

CREATE TABLE `PortletPreferences` (
  `portletPreferencesId` bigint(20) NOT NULL,
  `ownerId` bigint(20) DEFAULT NULL,
  `ownerType` int(11) DEFAULT NULL,
  `plid` bigint(20) DEFAULT NULL,
  `portletId` varchar(200) DEFAULT NULL,
  `preferences` longtext DEFAULT NULL,
  `mvccVersion` bigint(20) NOT NULL DEFAULT 0,
  `companyId` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`portletPreferencesId`),
  UNIQUE KEY `IX_C7057FF7` (`ownerId`,`ownerType`,`plid`,`portletId`),

mysql 덤프 파일에는 다음 두 항목이 표시됩니다.

(31453178,0,3,30168717,'com_liferay_product_navigation_product_menu_web_portlet_ProductMenuPortlet','<portlet-preferences />',0,10132)
(31524539,0,3,30168717,'com_liferay_product_navigation_product_menu_web_portlet_ProductMenuPortlet','<portlet-preferences />',0,10132)

네, 동일한 고유 키를 가진 두 개의 항목이 있습니다.어떻게 그게 가능합니까?!?

이를 알고 소스 DB에 대해 다음 select 문을 실행했습니다.

select portletPreferencesId, ownerId, ownerType, plid, portletId from PortletPreferences where ownerId = 0 AND ownerType = 3 AND plid = 30168717 AND portletId like 'com_liferay_product_navigation_product_menu_web%';

그리고 한 줄만 출력합니다!

+----------------------+---------+-----------+----------+----------------------------------------------------------------------------+
| portletPreferencesId | ownerId | ownerType | plid | portletId |
+----------------------+---------+-----------+----------+----------------------------------------------------------------------------+
| 31524539 | 0 | 3 | 30168717 | com_liferay_product_navigation_product_menu_web_portlet_ProductMenuPortlet |
+----------------------+---------+-----------+----------+----------------------------------------------------------------------------+

바이 더portletPreferencesId필드는 덤프 파일의 두 번째 항목을 출력합니다.그래서 다른 행을 하나 더 선택했습니다.

select portletPreferencesId, ownerId, ownerType, plid, portletId from PortletPreferences where portletPreferencesId = 31453178;

그리고 저는 다음을 얻습니다.

+----------------------+---------+-----------+----------+----------------------------------------------------------------------------+
| portletPreferencesId | ownerId | ownerType | plid | portletId |
+----------------------+---------+-----------+----------+----------------------------------------------------------------------------+
| 31453178 | 0 | 3 | 30168717 | com_liferay_product_navigation_product_menu_web_portlet_ProductMenuPortlet |
+----------------------+---------+-----------+----------+----------------------------------------------------------------------------+

내 질문은, 무슨 일이야?!?첫 번째 select 문에서 해당 항목이 출력되지 않는 이유는 무엇이며, 해당 필드가 고유해야 하는 경우에는 왜 애초에 해당 항목이 존재합니까?

소스 데이터베이스의 상태에 대해 좋지 않은 느낌이 듭니다 :-( 아, 그리고 그것은 하나입니다.나는 그 테이블에 그런 중복된 키가 여러 개 있습니다 :-(

감사해요.

MDEV-15250과 같은 버그로 인해 중복 항목이 발생할 수 있습니다.

때때로 고유 제약 조건 때문에 최적화 도구의 일부가 단일 행만 기대하므로 행 너머로 검색하지 않을 수 있습니다.항목을 포함한 범위에 걸친 쿼리가 더 많이 표시될 수 있습니다(이것이 mysqdump가 수행한 작업입니다).

만약 당신이 그것과 관련이 없다고 생각한다면.ALTER TABLEMDEV-15250과 같이 삽입과 동시에 발생하며, 고유한 키 시행에서 벗어날 수 있는 테이블의 작업 집합으로 좋은 예감이 듭니다. 버그 보고서를 작성해 주시겠습니까?

언급URL : https://stackoverflow.com/questions/71149325/weird-behavior-in-mariadb-table-with-unique-key-defined-ie-not-so-unique

반응형