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

[batch] A procedure to rename job_groups_cancelled.id -> job_groups_cancelled.batch_id #14672

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion batch/batch/driver/instance_collection/job_private.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ async def user_runnable_jobs(user, remaining) -> AsyncIterator[Dict[str, Any]]:
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_groups.batch_id = job_group_self_and_ancestors.batch_id AND
job_groups.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down
4 changes: 2 additions & 2 deletions batch/batch/driver/instance_collection/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ async def regions_to_ready_cores_mcpu_from_estimated_job_queue(self) -> List[Tup
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE jobs.batch_id = job_group_self_and_ancestors.batch_id AND
jobs.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down Expand Up @@ -622,7 +622,7 @@ async def user_runnable_jobs(user):
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_groups.batch_id = job_group_self_and_ancestors.batch_id AND
job_groups.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down
4 changes: 2 additions & 2 deletions batch/batch/driver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ async def check(tx):
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_groups.batch_id = job_group_self_and_ancestors.batch_id AND
job_groups.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down Expand Up @@ -1312,7 +1312,7 @@ async def cancel_fast_failing_job_groups(app):
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_groups.batch_id = job_group_self_and_ancestors.batch_id AND
job_groups.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down
6 changes: 3 additions & 3 deletions batch/batch/front_end/front_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ async def _create_job_group(
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_group_self_and_ancestors.batch_id = %s AND job_group_self_and_ancestors.job_group_id = %s;
""",
Expand Down Expand Up @@ -1984,7 +1984,7 @@ async def _get_job_group(app, batch_id: int, job_group_id: int) -> GetJobGroupRe
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_groups.batch_id = job_group_self_and_ancestors.batch_id AND
job_groups.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down Expand Up @@ -2086,7 +2086,7 @@ async def close_batch(request, userdata):
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_groups.batch_id = job_group_self_and_ancestors.batch_id AND
job_groups.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down
4 changes: 2 additions & 2 deletions batch/batch/front_end/query/query_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def parse_list_batches_query_v1(user: str, q: str, last_batch_id: Optional[int])
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_groups.batch_id = job_group_self_and_ancestors.batch_id AND
job_groups.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down Expand Up @@ -171,7 +171,7 @@ def parse_list_job_groups_query_v1(
SELECT 1 AS cancelled
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE job_groups.batch_id = job_group_self_and_ancestors.batch_id AND
job_groups.job_group_id = job_group_self_and_ancestors.job_group_id
Expand Down
18 changes: 9 additions & 9 deletions batch/sql/estimated-current.sql
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ BEGIN

SET job_group_cancelled = EXISTS (SELECT TRUE
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE batch_id = NEW.batch_id AND job_group_self_and_ancestors.job_group_id = NEW.job_group_id
LOCK IN SHARE MODE);
Expand Down Expand Up @@ -671,7 +671,7 @@ BEGIN

SET cur_job_group_cancelled = EXISTS (SELECT TRUE
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE batch_id = OLD.batch_id AND job_group_self_and_ancestors.job_group_id = OLD.job_group_id
LOCK IN SHARE MODE);
Expand Down Expand Up @@ -1107,7 +1107,7 @@ BEGIN

SET cur_cancelled = EXISTS (SELECT TRUE
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE batch_id = in_batch_id AND job_group_self_and_ancestors.job_group_id = in_job_group_id
FOR UPDATE);
Expand Down Expand Up @@ -1256,10 +1256,10 @@ BEGIN
WHERE batch_id = in_batch_id AND job_id = in_job_id
FOR UPDATE;

SELECT (jobs.cancelled OR job_groups_cancelled.id IS NOT NULL) AND NOT jobs.always_run
SELECT (jobs.cancelled OR job_groups_cancelled.batch_id IS NOT NULL) AND NOT jobs.always_run
INTO cur_job_cancel
FROM jobs
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.id = jobs.batch_id
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.batch_id = jobs.batch_id
WHERE batch_id = in_batch_id AND job_id = in_job_id
LOCK IN SHARE MODE;

Expand Down Expand Up @@ -1376,10 +1376,10 @@ BEGIN
WHERE batch_id = in_batch_id AND job_id = in_job_id
FOR UPDATE;

SELECT (jobs.cancelled OR job_groups_cancelled.id IS NOT NULL) AND NOT jobs.always_run
SELECT (jobs.cancelled OR job_groups_cancelled.batch_id IS NOT NULL) AND NOT jobs.always_run
INTO cur_job_cancel
FROM jobs
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.id = jobs.batch_id
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.batch_id = jobs.batch_id
WHERE batch_id = in_batch_id AND job_id = in_job_id
LOCK IN SHARE MODE;

Expand Down Expand Up @@ -1421,10 +1421,10 @@ BEGIN
WHERE batch_id = in_batch_id AND job_id = in_job_id
FOR UPDATE;

SELECT (jobs.cancelled OR job_groups_cancelled.id IS NOT NULL) AND NOT jobs.always_run
SELECT (jobs.cancelled OR job_groups_cancelled.batch_id IS NOT NULL) AND NOT jobs.always_run
INTO cur_job_cancel
FROM jobs
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.id = jobs.batch_id
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.batch_id = jobs.batch_id
WHERE batch_id = in_batch_id AND job_id = in_job_id
LOCK IN SHARE MODE;

Expand Down
6 changes: 3 additions & 3 deletions batch/sql/finalize-job-groups.sql
ichengchang marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BEGIN

SET job_group_cancelled = EXISTS (SELECT TRUE
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE batch_id = NEW.batch_id AND job_group_self_and_ancestors.job_group_id = NEW.job_group_id
LOCK IN SHARE MODE);
Expand Down Expand Up @@ -142,7 +142,7 @@ BEGIN

SET cur_job_group_cancelled = EXISTS (SELECT TRUE
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE batch_id = OLD.batch_id AND job_group_self_and_ancestors.job_group_id = OLD.job_group_id
LOCK IN SHARE MODE);
Expand Down Expand Up @@ -318,7 +318,7 @@ BEGIN

SET cur_cancelled = EXISTS (SELECT TRUE
FROM job_group_self_and_ancestors
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.id AND
INNER JOIN job_groups_cancelled ON job_group_self_and_ancestors.batch_id = job_groups_cancelled.batch_id AND
job_group_self_and_ancestors.ancestor_id = job_groups_cancelled.job_group_id
WHERE batch_id = in_batch_id AND job_group_self_and_ancestors.job_group_id = in_job_group_id
FOR UPDATE);
Expand Down
103 changes: 103 additions & 0 deletions batch/sql/rename-job-groups-cancelled-column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
DELIMITER $$

Check failure on line 1 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L1

syntax error at or near "DELIMITER"

CREATE PROCEDURE IF NOT EXISTS rename_job_groups_cancelled_column(
IN from_column VARCHAR(64),
IN to_column VARCHAR(64)
)
rename_column:BEGIN
DECLARE v_constraint_name VARCHAR(64);
DECLARE v_done INT DEFAULT FALSE;

Check failure on line 9 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L9

syntax error at or near "INT"
DECLARE v_error_message TEXT;

Check failure on line 10 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L10

syntax error at or near "TEXT"
DECLARE v_primary_exists INT DEFAULT FALSE;

Check failure on line 11 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L11

syntax error at or near "INT"
DECLARE v_sqlstate CHAR(5);

Check failure on line 12 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L12

syntax error at or near "CHAR"

-- Dynamically fetch the names of contraints related to `from_column`
DECLARE v_cursor CURSOR FOR
SELECT CONSTRAINT_NAME
FROM information_schema.KEY_COLUMN_USAGE
WHERE TABLE_NAME = 'job_groups_cancelled'
AND COLUMN_NAME = from_column;

-- Rollback handler if something goes wrong
DECLARE EXIT HANDLER FOR SQLEXCEPTION

Check failure on line 22 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L22

syntax error at or near "HANDLER"
BEGIN
GET DIAGNOSTICS CONDITION 1
v_sqlstate = RETURNED_SQLSTATE,
v_error_message = MESSAGE_TEXT;

SELECT CONCAT('Error SQLSTATE: ', v_sqlstate, ', Message: ', v_error_message) AS ErrorDetails;

ROLLBACK;
END;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;

Check failure on line 33 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L33

syntax error at or near "HANDLER"

-- Check if `from_column` exists and `to_column` does not exist
IF NOT EXISTS (SELECT * FROM information_schema.COLUMNS

Check failure on line 36 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L36

syntax error at or near "IF"
WHERE TABLE_NAME = 'job_groups_cancelled'
AND COLUMN_NAME = from_column) THEN
SELECT CONCAT('Error: Column ', from_column, ' does not exist.') AS ErrorDetails;
LEAVE rename_column;

Check failure on line 40 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L40

syntax error at or near "LEAVE"
END IF;

Check failure on line 41 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L41

syntax error at or near "IF"

IF EXISTS (SELECT * FROM information_schema.COLUMNS

Check failure on line 43 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L43

syntax error at or near "IF"
WHERE TABLE_NAME = 'job_groups_cancelled'
AND COLUMN_NAME = to_column) THEN
SELECT CONCAT('Error: Column ', to_column, ' already exists.') AS ErrorDetails;
LEAVE rename_column;
END IF;

START TRANSACTION;

OPEN v_cursor;

Check failure on line 52 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L52

syntax error at or near "OPEN"

drop_fk_loop: LOOP

Check failure on line 54 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L54

syntax error at or near "drop_fk_loop"

FETCH v_cursor INTO v_constraint_name;

IF v_done THEN

Check failure on line 58 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L58

syntax error at or near "IF"
LEAVE drop_fk_loop;
END IF;

SELECT v_constraint_name;

IF v_constraint_name = 'PRIMARY' THEN

Check failure on line 64 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L64

syntax error at or near "IF"
SET v_primary_exists = TRUE;
ELSE

Check failure on line 66 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L66

syntax error at or near "ELSE"
SET @sql = CONCAT('ALTER TABLE job_groups_cancelled DROP FOREIGN KEY ', v_constraint_name);
PREPARE stmt FROM @sql;

Check failure on line 68 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L68

syntax error at or near "FROM"
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;

END LOOP;

Check failure on line 73 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L73

syntax error at or near "LOOP"

CLOSE v_cursor;

-- drop primary key
IF v_primary_exists THEN

Check failure on line 78 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L78

syntax error at or near "IF"
SET @sql = 'ALTER TABLE job_groups_cancelled DROP PRIMARY KEY';
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;

-- rename column from `from_column` to `to_column`
SET @sql = CONCAT('ALTER TABLE job_groups_cancelled CHANGE COLUMN `', from_column, '` `', to_column, '` BIGINT NOT NULL');

Check failure on line 86 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L86

syntax error at or near "@"
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- Recreate the primary and foreign key constraints using `to_column`
SET @sql = CONCAT('ALTER TABLE job_groups_cancelled ADD PRIMARY KEY (`', to_column, '`, `job_group_id`), ',

Check failure on line 92 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L92

syntax error at or near "@"
'ADD FOREIGN KEY (`', to_column, '`) REFERENCES batches(`id`) ON DELETE CASCADE, ',
'ADD FOREIGN KEY (`', to_column, '`, `job_group_id`) REFERENCES job_groups(`batch_id`, `job_group_id`) ON DELETE CASCADE');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

COMMIT;

END $$

Check failure on line 101 in batch/sql/rename-job-groups-cancelled-column.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

batch/sql/rename-job-groups-cancelled-column.sql#L101

unterminated dollar-quoted string at or near "$$

DELIMITER ;
12 changes: 6 additions & 6 deletions batch/sql/rename-job-groups-tables.sql
ichengchang marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@ BEGIN
WHERE batch_id = in_batch_id AND job_id = in_job_id
FOR UPDATE;

SELECT (jobs.cancelled OR job_groups_cancelled.id IS NOT NULL) AND NOT jobs.always_run
SELECT (jobs.cancelled OR job_groups_cancelled.batch_id IS NOT NULL) AND NOT jobs.always_run
INTO cur_job_cancel
FROM jobs
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.id = jobs.batch_id
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.batch_id = jobs.batch_id
WHERE batch_id = in_batch_id AND job_id = in_job_id
LOCK IN SHARE MODE;

Expand Down Expand Up @@ -669,10 +669,10 @@ BEGIN
WHERE batch_id = in_batch_id AND job_id = in_job_id
FOR UPDATE;

SELECT (jobs.cancelled OR job_groups_cancelled.id IS NOT NULL) AND NOT jobs.always_run
SELECT (jobs.cancelled OR job_groups_cancelled.batch_id IS NOT NULL) AND NOT jobs.always_run
INTO cur_job_cancel
FROM jobs
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.id = jobs.batch_id
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.batch_id = jobs.batch_id
WHERE batch_id = in_batch_id AND job_id = in_job_id
LOCK IN SHARE MODE;

Expand Down Expand Up @@ -714,10 +714,10 @@ BEGIN
WHERE batch_id = in_batch_id AND job_id = in_job_id
FOR UPDATE;

SELECT (jobs.cancelled OR job_groups_cancelled.id IS NOT NULL) AND NOT jobs.always_run
SELECT (jobs.cancelled OR job_groups_cancelled.batch_id IS NOT NULL) AND NOT jobs.always_run
INTO cur_job_cancel
FROM jobs
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.id = jobs.batch_id
LEFT JOIN job_groups_cancelled ON job_groups_cancelled.batch_id = jobs.batch_id
WHERE batch_id = in_batch_id AND job_id = in_job_id
LOCK IN SHARE MODE;

Expand Down