Give orderToAuthz2 an auto-increment ID column (#6835)

Replace the current orderToAuthz2 table schema with one that includes an
auto-increment ID column, so that this table can be partitioned simply
by ID, like all of our other partitioned tables.

Update the SA so that when it selects from a join over this table and
the authz2 table, it explicitly selects the columns from the authz2
table, to avoid the ambiguity introduced by having two columns named
"id" in the result set.

This work is already in-progress in prod, represented by IN-8916 and
IN-8928.

Fixes https://github.com/letsencrypt/boulder/issues/6820
This commit is contained in:
Aaron Gable 2023-04-24 14:59:18 -07:00 committed by GitHub
parent 43bb293d6f
commit 97aa50977f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,27 @@
-- +migrate Up
-- SQL in section 'Up' is executed when this migration is applied
DROP TABLE orderToAuthz2;
CREATE TABLE `orderToAuthz2` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`orderID` bigint(20) UNSIGNED NOT NULL,
`authzID` bigint(20) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
KEY `orderID_idx` (`orderID`),
KEY `authzID_idx` (`authzID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4
PARTITION BY RANGE (`id`)
(PARTITION p_start VALUES LESS THAN (MAXVALUE));
-- +migrate Down
-- SQL section 'Down' is executed when this migration is rolled back
DROP TABLE orderToAuthz2;
CREATE TABLE `orderToAuthz2` (
`orderID` bigint(20) NOT NULL,
`authzID` bigint(20) NOT NULL,
PRIMARY KEY (`orderID`,`authzID`),
KEY `authzID` (`authzID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
PARTITION BY RANGE COLUMNS(orderID, authzID)
(PARTITION p_start VALUES LESS THAN (MAXVALUE, MAXVALUE));

View File

@ -994,6 +994,16 @@ func (ssa *SQLStorageAuthorityRO) GetValidOrderAuthorizations2(ctx context.Conte
return nil, errIncompleteRequest
}
// The authz2 and orderToAuthz2 tables both have a column named "id", so we
// need to be explicit about which table's "id" column we want to select.
qualifiedAuthzFields := strings.Split(authzFields, " ")
for i, field := range qualifiedAuthzFields {
if field == "id," {
qualifiedAuthzFields[i] = "authz2.id,"
break
}
}
var ams []authzModel
_, err := ssa.dbReadOnlyMap.WithContext(ctx).Select(
&ams,
@ -1003,7 +1013,7 @@ func (ssa *SQLStorageAuthorityRO) GetValidOrderAuthorizations2(ctx context.Conte
authz2.expires > :expires AND
authz2.status = :status AND
orderToAuthz2.orderID = :orderID`,
authzFields,
strings.Join(qualifiedAuthzFields, " "),
),
map[string]interface{}{
"regID": req.AcctID,