Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to parse MySQL ddl from composite index #294

Open
finnou0817 opened this issue Jan 20, 2025 · 1 comment
Open

Fail to parse MySQL ddl from composite index #294

finnou0817 opened this issue Jan 20, 2025 · 1 comment

Comments

@finnou0817
Copy link

finnou0817 commented Jan 20, 2025

Describe the bug
Here is a bug with MySQL composite index. There is the first column of index is recorded, but miss the following columns.

To Reproduce
Steps to reproduce the behavior:

  1. MySQL example dialect with composite index
CREATE TABLE `employee` (
  `employee_id` int NOT NULL,
  `first_name` varchar(50) NOT NULL,
  `last_name` varchar(50) NOT NULL,
  `email` varchar(100) NOT NULL,
  `phone_number` varchar(20) DEFAULT NULL,
  `hire_date` date NOT NULL,
  `job_id` int NOT NULL,
  `department_id` int DEFAULT NULL,
  `manager_id` int DEFAULT NULL,
  `salary` decimal(10,2) DEFAULT NULL,
  PRIMARY KEY (`employee_id`),
  KEY `composite_full_name` (`first_name`,`last_name`),
  KEY `idx_job_id` (`job_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
  1. Parse the dialect with DDLParser
parser_output = DDLParser(ddl).run(output_mode="mysql")
  1. Parsing result will miss the secondary column of composite index
{
   "table_name":"`employee`",
   "schema":"None",
   "primary_key":[
      "`employee_id`"
   ],
   "columns":[
      {
         "name":"`employee_id`",
         "type":"int",
         "size":"None",
         "references":"None",
         "unique":false,
         "nullable":false,
         "default":"None",
         "check":"None"
      },
      {
         "name":"`first_name`",
         "type":"varchar",
         "size":50,
         "references":"None",
         "unique":false,
         "nullable":false,
         "default":"None",
         "check":"None"
      },
      {
         "name":"`last_name`",
         "type":"varchar",
         "size":50,
         "references":"None",
         "unique":false,
         "nullable":false,
         "default":"None",
         "check":"None"
      },
      {
         "name":"`email`",
         "type":"varchar",
         "size":100,
         "references":"None",
         "unique":false,
         "nullable":false,
         "default":"None",
         "check":"None"
      },
      {
         "name":"`phone_number`",
         "type":"varchar",
         "size":20,
         "references":"None",
         "unique":false,
         "nullable":true,
         "default":"NULL",
         "check":"None"
      },
      {
         "name":"`hire_date`",
         "type":"date",
         "size":"None",
         "references":"None",
         "unique":false,
         "nullable":false,
         "default":"None",
         "check":"None"
      },
      {
         "name":"`job_id`",
         "type":"int",
         "size":"None",
         "references":"None",
         "unique":false,
         "nullable":false,
         "default":"None",
         "check":"None"
      },
      {
         "name":"`department_id`",
         "type":"int",
         "size":"None",
         "references":"None",
         "unique":false,
         "nullable":true,
         "default":"NULL",
         "check":"None"
      },
      {
         "name":"`manager_id`",
         "type":"int",
         "size":"None",
         "references":"None",
         "unique":false,
         "nullable":true,
         "default":"NULL",
         "check":"None"
      },
      {
         "name":"`salary`",
         "type":"decimal",
         "size":(10,
         2),
         "references":"None",
         "unique":false,
         "nullable":true,
         "default":"NULL",
         "check":"None"
      }
   ],
   "alter":{
      
   },
   "checks":[
      
   ],
   "index":[
      {
         "clustered":false,
         "columns":[
            "`first_name`"
         ],
         "detailed_columns":[
            {
               "name":"`first_name`",
               "nulls":"LAST",
               "order":"ASC"
            }
         ],
         "index_name":"`composite_full_name`",
         "unique":false
      },
      {
         "clustered":false,
         "columns":[
            "`job_id`"
         ],
         "detailed_columns":[
            {
               "name":"`job_id`",
               "nulls":"LAST",
               "order":"ASC"
            }
         ],
         "index_name":"`idx_job_id`",
         "unique":false
      }
   ],
   "partitioned_by":[
      
   ],
   "tablespace":"None",
   "table_properties":{
      "collate":"utf8mb4_0900_ai_ci"
   },
   "engine":"InnoDB",
   "default_charset":"utf8mb4"
}{
   "comments":[
      "!40101 SET @saved_cs_client     = @@character_set_client */;",
      "!50503 SET character_set_client = utf8mb4 */;",
      "!40101 SET character_set_client = @saved_cs_client */;"
   ]
}

Expected behavior

{
   ...
   "index":[
      {
         "clustered":false,
         "columns":[
            "`first_name`"
         ],
         "detailed_columns":[
            {
               "name":"`first_name`",
               "nulls":"LAST",
               "order":"ASC"
            },
            **{
               "name":"`last_name`",
               "nulls":"LAST",
               "order":"ASC"
            }**
         ],
         "index_name":"`composite_full_name`",
         "unique":false
      },
      {
         "clustered":false,
         "columns":[
            "`job_id`"
         ],
         "detailed_columns":[
            {
               "name":"`job_id`",
               "nulls":"LAST",
               "order":"ASC"
            }
         ],
         "index_name":"`idx_job_id`",
         "unique":false
      }
   ],
   ...
}

Desktop (please complete the following information):

  • OS: MacOS (Apple M1)
@finnou0817 finnou0817 changed the title Fail to parsing ddl from composite index Fail to parse ddl from composite index Jan 20, 2025
@finnou0817 finnou0817 changed the title Fail to parse ddl from composite index Fail to parse MySQL ddl from composite index Jan 20, 2025
@xnuinside
Copy link
Owner

@finnou0817 thanks for reporting the issue, I will try to fix on the weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants