From 97aa50977fb55c859342c9fabc636fc35a388aac Mon Sep 17 00:00:00 2001 From: Aaron Gable Date: Mon, 24 Apr 2023 14:59:18 -0700 Subject: [PATCH] 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 --- .../20230419000003_OrderToAuthzID.sql | 27 +++++++++++++++++++ sa/saro.go | 12 ++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 sa/db-next/boulder_sa/20230419000003_OrderToAuthzID.sql diff --git a/sa/db-next/boulder_sa/20230419000003_OrderToAuthzID.sql b/sa/db-next/boulder_sa/20230419000003_OrderToAuthzID.sql new file mode 100644 index 000000000..2a2ab06cc --- /dev/null +++ b/sa/db-next/boulder_sa/20230419000003_OrderToAuthzID.sql @@ -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)); diff --git a/sa/saro.go b/sa/saro.go index 3817e3217..401cabef2 100644 --- a/sa/saro.go +++ b/sa/saro.go @@ -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,