ephraimbuddy commented on a change in pull request #21462:
URL: https://github.com/apache/airflow/pull/21462#discussion_r803157245



##########
File path: airflow/models/taskinstance.py
##########
@@ -386,6 +385,7 @@ class TaskInstance(Base, LoggingMixin):
         Index('ti_pool', pool, state, priority_weight),
         Index('ti_job_id', job_id),
         Index('ti_trigger_id', trigger_id),
+        Index('ti_map_index', dag_id, task_id, run_id, map_index, unique=True),

Review comment:
       Both MySQL and MSSQL required this. Here is the error from MySQL:
   ```sql
   sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) 
(1822, "Failed to add the foreign key constraint. Missing index for constraint 
'task_map_task_instance_fkey' in the referenced table 'task_instance'")
   [SQL: 
   CREATE TABLE task_map (
           dag_id VARCHAR(250) COLLATE utf8mb3_bin NOT NULL, 
           task_id VARCHAR(250) COLLATE utf8mb3_bin NOT NULL, 
           run_id VARCHAR(250) COLLATE utf8mb3_bin NOT NULL, 
           map_index INTEGER NOT NULL, 
           length INTEGER NOT NULL, 
           `keys` JSON, 
           PRIMARY KEY (dag_id, task_id, run_id, map_index), 
           CONSTRAINT task_map_length_not_negative CHECK (length >= 0), 
           CONSTRAINT task_map_task_instance_fkey FOREIGN KEY(dag_id, task_id, 
run_id, map_index) REFERENCES task_instance (dag_id, task_id, run_id, 
map_index) ON DELETE CASCADE
   )
   ```
   The unique=True was required by MSSQL:
   ```sql
   sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', 
"[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]There are no 
primary or candidate keys in the referenced table 'task_instance' that match 
the referencing column list in the foreign key 'task_map_task_instance_fkey'. 
(1776) (SQLExecDirectW)")
   [SQL: 
   CREATE TABLE task_map (
           dag_id VARCHAR(250) NOT NULL, 
           task_id VARCHAR(250) NOT NULL, 
           run_id VARCHAR(250) NOT NULL, 
           map_index INTEGER NOT NULL, 
           length INTEGER NOT NULL, 
           keys NVARCHAR(max) NULL, 
           PRIMARY KEY (dag_id, task_id, run_id, map_index), 
           CONSTRAINT task_map_length_not_negative CHECK (length >= 0), 
           CONSTRAINT task_map_task_instance_fkey FOREIGN KEY(dag_id, task_id, 
run_id, map_index) REFERENCES task_instance (dag_id, task_id, run_id, 
map_index) ON DELETE CASCADE
   )
   ```
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to