@@ -1152,20 +1152,15 @@ CREATE TABLE crdb_internal.jobs (
1152
1152
description STRING,
1153
1153
statement STRING,
1154
1154
user_name STRING,
1155
- descriptor_ids INT[],
1156
1155
status STRING,
1157
1156
running_status STRING,
1158
1157
created TIMESTAMPTZ,
1159
- started TIMESTAMPTZ,
1160
1158
finished TIMESTAMPTZ,
1161
1159
modified TIMESTAMPTZ,
1162
1160
fraction_completed FLOAT,
1163
1161
high_water_timestamp DECIMAL,
1164
1162
error STRING,
1165
1163
coordinator_id INT,
1166
- trace_id INT,
1167
- execution_errors STRING[],
1168
- execution_events JSONB,
1169
1164
INDEX(job_id),
1170
1165
INDEX(status),
1171
1166
INDEX(job_type)
@@ -1223,8 +1218,11 @@ j.error_msg,
1223
1218
j.claim_instance_id
1224
1219
FROM system.public.jobs AS j
1225
1220
LEFT OUTER JOIN system.public.job_progress AS p ON j.id = p.job_id
1226
- LEFT OUTER JOIN system.public.job_status AS s ON j.id = s.job_id
1227
- ` + whereClause
1221
+ LEFT OUTER JOIN system.public.job_status AS s ON j.id = s.job_id
1222
+ ` + whereClause + `UNION
1223
+ (SELECT job_id, job_type, description, user_name, 'pending',
1224
+ NULL, now(), NULL, now(), NULL, NULL, NULL, NULL
1225
+ FROM crdb_internal.session_pending_jobs())`
1228
1226
1229
1227
it , err := p .InternalSQLTxn ().QueryIteratorEx (
1230
1228
ctx , "system-jobs-join" , p .txn , sessiondata .NodeUserSessionDataOverride , query , params ... )
@@ -1237,108 +1235,60 @@ LEFT OUTER JOIN system.public.job_status AS s ON j.id = s.job_id
1237
1235
}
1238
1236
}()
1239
1237
1240
- sessionJobs := make ([]* jobs.Record , 0 , p .extendedEvalCtx .jobs .numToCreate ())
1241
- uniqueJobs := make (map [* jobs.Record ]struct {})
1242
- if err := p .extendedEvalCtx .jobs .forEachToCreate (func (job * jobs.Record ) error {
1243
- if _ , ok := uniqueJobs [job ]; ok {
1244
- return nil
1245
- }
1246
- sessionJobs = append (sessionJobs , job )
1247
- uniqueJobs [job ] = struct {}{}
1248
- return nil
1249
- }); err != nil {
1250
- return emitted , err
1251
- }
1252
-
1253
1238
// Loop while we need to skip a row.
1254
1239
for {
1255
1240
ok , err := it .Next (ctx )
1256
- if err != nil {
1241
+ if err != nil || ! ok {
1257
1242
return emitted , err
1258
1243
}
1259
- // We will read the columns from the query on joined jobs tables into a wide
1260
- // row, and then copy the values from read rows into named variables to then
1261
- // use when emitting our output row. If we need to synthesize rows for jobs
1262
- // pending creation in the session, we'll do so in those same named vars to
1263
- // keep things organized.
1264
- // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
1265
- var id , typStr , desc , ownerStr , state , status , created , finished , modified , fraction , resolved , errorMsg , instanceID tree.Datum
1244
+ r := it .Cur ()
1245
+ id , typStr , desc , ownerStr , state , status , created , finished , modified , fraction , resolved , errorMsg , instanceID :=
1246
+ r [0 ], r [1 ], r [2 ], r [3 ], r [4 ], r [5 ], r [6 ], r [7 ], r [8 ], r [9 ], r [10 ], r [11 ], r [12 ]
1266
1247
1267
- if ok {
1268
- r := it .Cur ()
1269
- id , typStr , desc , ownerStr , state , status , created , finished , modified , fraction , resolved , errorMsg , instanceID =
1270
- r [0 ], r [1 ], r [2 ], r [3 ], r [4 ], r [5 ], r [6 ], r [7 ], r [8 ], r [9 ], r [10 ], r [11 ], r [12 ]
1248
+ owner := username .MakeSQLUsernameFromPreNormalizedString (string (tree .MustBeDString (ownerStr )))
1249
+ jobID := jobspb .JobID (tree .MustBeDInt (id ))
1250
+ typ , err := jobspb .TypeFromString (string (tree .MustBeDString (typStr )))
1251
+ if err != nil {
1252
+ return emitted , err
1253
+ }
1271
1254
1272
- owner := username .MakeSQLUsernameFromPreNormalizedString (string (tree .MustBeDString (ownerStr )))
1273
- jobID := jobspb .JobID (tree .MustBeDInt (id ))
1274
- typ , err := jobspb .TypeFromString (string (tree .MustBeDString (typStr )))
1255
+ getLegacyPayloadForAuth := func (ctx context.Context ) (* jobspb.Payload , error ) {
1256
+ if ! enablePerJobDetailedAuthLookups .Get (& p .EvalContext ().Settings .SV ) {
1257
+ return nil , errLegacyPerJobAuthDisabledSentinel
1258
+ }
1259
+ if p .EvalContext ().Settings .Version .IsActive (ctx , clusterversion .V25_1 ) {
1260
+ log .Warningf (ctx , "extended job access control based on job-specific details is deprecated and can make SHOW JOBS less performant; consider disabling %s" ,
1261
+ enablePerJobDetailedAuthLookups .Name ())
1262
+ p .BufferClientNotice (ctx ,
1263
+ pgnotice .Newf ("extended job access control based on job-specific details has been deprecated and can make SHOW JOBS less performant; consider disabling %s" ,
1264
+ enablePerJobDetailedAuthLookups .Name ()))
1265
+ }
1266
+ payload := & jobspb.Payload {}
1267
+ infoStorage := jobs .InfoStorageForJob (p .InternalSQLTxn (), jobID )
1268
+ payloadBytes , exists , err := infoStorage .GetLegacyPayload (ctx , "getLegacyPayload-for-custom-auth" )
1275
1269
if err != nil {
1276
- return emitted , err
1270
+ return nil , err
1277
1271
}
1278
-
1279
- getLegacyPayloadForAuth := func (ctx context.Context ) (* jobspb.Payload , error ) {
1280
- if ! enablePerJobDetailedAuthLookups .Get (& p .EvalContext ().Settings .SV ) {
1281
- return nil , errLegacyPerJobAuthDisabledSentinel
1282
- }
1283
- if p .EvalContext ().Settings .Version .IsActive (ctx , clusterversion .V25_1 ) {
1284
- log .Warningf (ctx , "extended job access control based on job-specific details is deprecated and can make SHOW JOBS less performant; consider disabling %s" ,
1285
- enablePerJobDetailedAuthLookups .Name ())
1286
- p .BufferClientNotice (ctx ,
1287
- pgnotice .Newf ("extended job access control based on job-specific details has been deprecated and can make SHOW JOBS less performant; consider disabling %s" ,
1288
- enablePerJobDetailedAuthLookups .Name ()))
1289
- }
1290
- payload := & jobspb.Payload {}
1291
- infoStorage := jobs .InfoStorageForJob (p .InternalSQLTxn (), jobID )
1292
- payloadBytes , exists , err := infoStorage .GetLegacyPayload (ctx , "getLegacyPayload-for-custom-auth" )
1293
- if err != nil {
1294
- return nil , err
1295
- }
1296
- if ! exists {
1297
- return nil , errors .New ("job payload not found in system.job_info" )
1298
- }
1299
- if err := protoutil .Unmarshal (payloadBytes , payload ); err != nil {
1300
- return nil , err
1301
- }
1302
- return payload , nil
1272
+ if ! exists {
1273
+ return nil , errors .New ("job payload not found in system.job_info" )
1303
1274
}
1304
- if errorMsg == tree . DNull {
1305
- errorMsg = emptyString
1275
+ if err := protoutil . Unmarshal ( payloadBytes , payload ); err != nil {
1276
+ return nil , err
1306
1277
}
1278
+ return payload , nil
1279
+ }
1280
+ if errorMsg == tree .DNull {
1281
+ errorMsg = emptyString
1282
+ }
1307
1283
1308
- if err := jobsauth .AuthorizeAllowLegacyAuth (
1309
- ctx , p , jobID , getLegacyPayloadForAuth , owner , typ , jobsauth .ViewAccess , globalPrivileges ,
1310
- ); err != nil {
1311
- // Filter out jobs which the user is not allowed to see.
1312
- if IsInsufficientPrivilegeError (err ) {
1313
- continue
1314
- }
1315
- return emitted , err
1316
- }
1317
- } else if ! ok {
1318
- if len (sessionJobs ) == 0 {
1319
- return emitted , nil
1284
+ if err := jobsauth .AuthorizeAllowLegacyAuth (
1285
+ ctx , p , jobID , getLegacyPayloadForAuth , owner , typ , jobsauth .ViewAccess , globalPrivileges ,
1286
+ ); err != nil {
1287
+ // Filter out jobs which the user is not allowed to see.
1288
+ if IsInsufficientPrivilegeError (err ) {
1289
+ continue
1320
1290
}
1321
- job := sessionJobs [len (sessionJobs )- 1 ]
1322
- sessionJobs = sessionJobs [:len (sessionJobs )- 1 ]
1323
- payloadType , err := jobspb .DetailsType (jobspb .WrapPayloadDetails (job .Details ))
1324
- if err != nil {
1325
- return emitted , err
1326
- }
1327
- // synthesize the fields we'd read from the jobs table if this job were in it.
1328
- id , typStr , desc , ownerStr , state , status , created , finished , modified , fraction , resolved , errorMsg , instanceID =
1329
- tree .NewDInt (tree .DInt (job .JobID )),
1330
- tree .NewDString (payloadType .String ()),
1331
- tree .NewDString (job .Description ),
1332
- tree .NewDString (job .Username .Normalized ()),
1333
- tree .NewDString (string (jobs .StatePending )),
1334
- tree .DNull ,
1335
- tree .MustMakeDTimestampTZ (p .txn .ReadTimestamp ().GoTime (), time .Microsecond ),
1336
- tree .DNull ,
1337
- tree .MustMakeDTimestampTZ (p .txn .ReadTimestamp ().GoTime (), time .Microsecond ),
1338
- tree .NewDFloat (tree .DFloat (0 )),
1339
- tree .DZeroDecimal ,
1340
- tree .DNull ,
1341
- tree .NewDInt (tree .DInt (p .extendedEvalCtx .ExecCfg .JobRegistry .ID ()))
1291
+ return emitted , err
1342
1292
}
1343
1293
1344
1294
if err = addRow (
@@ -1347,20 +1297,15 @@ LEFT OUTER JOIN system.public.job_status AS s ON j.id = s.job_id
1347
1297
desc ,
1348
1298
desc ,
1349
1299
ownerStr ,
1350
- tree .DNull , // deperecated "descriptor_ids"
1351
1300
state ,
1352
1301
status ,
1353
1302
created ,
1354
- created , // deprecated "started" field.
1355
1303
finished ,
1356
1304
modified ,
1357
1305
fraction ,
1358
1306
resolved ,
1359
1307
errorMsg ,
1360
1308
instanceID ,
1361
- tree .DNull , // deprecated "trace_id" field.
1362
- tree .DNull , // deprecated "executionErrors" field.
1363
- tree .DNull , // deprecated "executionEvents" field.
1364
1309
); err != nil {
1365
1310
return emitted , err
1366
1311
}
0 commit comments