@@ -308,52 +308,41 @@ class TKikimrTransactionContextBase : public TThrRefBase {
308
308
309
309
bool hasScheme = false ;
310
310
bool hasData = false ;
311
- for (auto & [_, operation] : TableOperations) {
312
- hasScheme = hasScheme || (operation & KikimrSchemeOps ());
313
- hasData = hasData || (operation & KikimrDataOps ());
314
- }
315
-
316
- THashMap<TStringBuf, const NKqpProto::TKqpTableInfo*> tableInfoMap;
317
- tableInfoMap.reserve (tableInfos.size ());
318
- if (TableByIdMap.empty ()) {
319
- TableByIdMap.reserve (tableInfos.size ());
320
- }
321
- if (TableOperations.empty ()) {
322
- TableOperations.reserve (operations.size ());
311
+ for (auto & pair : TableOperations) {
312
+ hasScheme = hasScheme || (pair.second & KikimrSchemeOps ());
313
+ hasData = hasData || (pair.second & KikimrDataOps ());
323
314
}
324
315
316
+ THashMap<TString, NKqpProto::TKqpTableInfo> tableInfoMap;
325
317
for (const auto & info : tableInfos) {
326
- tableInfoMap.emplace ( info.GetTableName (), & info);
318
+ tableInfoMap.insert ( std::make_pair ( info.GetTableName (), info) );
327
319
328
320
TKikimrPathId pathId (info.GetTableId ().GetOwnerId (), info.GetTableId ().GetTableId ());
329
- TableByIdMap.emplace ( pathId, info.GetTableName ());
321
+ TableByIdMap.insert ( std::make_pair ( pathId, info.GetTableName () ));
330
322
}
331
323
332
324
for (const auto & op : operations) {
333
- const auto & table = [&]() -> const TString& {
334
- const auto tempTable = TempTables.FindPtr (op.GetTable ());
335
- if (tempTable) {
336
- return *tempTable;
337
- } else {
338
- return op.GetTable ();
339
- }
340
- }();
325
+ auto table = op.GetTable ();
341
326
342
- const auto newOp = TYdbOperation (op.GetOperation ());
327
+ auto newOp = TYdbOperation (op.GetOperation ());
328
+ TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
329
+
330
+ auto tempTable = TempTables.FindPtr (table);
331
+ if (tempTable) {
332
+ table = *tempTable;
333
+ }
343
334
344
335
const auto info = tableInfoMap.FindPtr (table);
345
336
if (!info) {
346
337
TString message = TStringBuilder ()
347
338
<< " Unable to find table info for table '" << table << " '" ;
348
- const TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
349
339
issues.AddIssue (YqlIssue (pos, TIssuesIds::KIKIMR_SCHEME_ERROR, message));
350
340
return {false , issues};
351
341
}
352
342
353
343
if (queryType == EKikimrQueryType::Dml && (newOp & KikimrSchemeOps ())) {
354
344
TString message = TStringBuilder () << " Operation '" << newOp
355
345
<< " ' can't be performed in data query" ;
356
- const TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
357
346
issues.AddIssue (YqlIssue (pos, TIssuesIds::KIKIMR_BAD_OPERATION, message));
358
347
return {false , issues};
359
348
}
@@ -362,7 +351,6 @@ class TKikimrTransactionContextBase : public TThrRefBase {
362
351
if (EffectiveIsolationLevel) {
363
352
TString message = TStringBuilder () << " Scheme operations can't be performed inside transaction, "
364
353
<< " operation: " << newOp;
365
- const TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
366
354
issues.AddIssue (YqlIssue (pos, TIssuesIds::KIKIMR_BAD_OPERATION, message));
367
355
return {false , issues};
368
356
}
@@ -371,15 +359,13 @@ class TKikimrTransactionContextBase : public TThrRefBase {
371
359
if (queryType == EKikimrQueryType::Ddl && (newOp & KikimrDataOps ())) {
372
360
TString message = TStringBuilder () << " Operation '" << newOp
373
361
<< " ' can't be performed in scheme query" ;
374
- const TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
375
362
issues.AddIssue (YqlIssue (pos, TIssuesIds::KIKIMR_BAD_OPERATION, message));
376
363
return {false , issues};
377
364
}
378
365
379
366
if (queryType == EKikimrQueryType::Scan && (newOp & KikimrModifyOps ())) {
380
367
TString message = TStringBuilder () << " Operation '" << newOp
381
368
<< " ' can't be performed in scan query" ;
382
- const TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
383
369
issues.AddIssue (YqlIssue (pos, TIssuesIds::KIKIMR_BAD_OPERATION, message));
384
370
return {false , issues};
385
371
}
@@ -393,28 +379,26 @@ class TKikimrTransactionContextBase : public TThrRefBase {
393
379
message = TStringBuilder () << message
394
380
<< " Use COMMIT statement to indicate end of transaction between scheme and data operations." ;
395
381
}
396
- const TPosition pos (op. GetPosition (). GetColumn (), op. GetPosition (). GetRow ());
382
+
397
383
issues.AddIssue (YqlIssue (pos, TIssuesIds::KIKIMR_MIXED_SCHEME_DATA_TX, message));
398
384
return {false , issues};
399
385
}
400
386
401
387
if (Readonly && (newOp & KikimrModifyOps ())) {
402
388
TString message = TStringBuilder () << " Operation '" << newOp
403
389
<< " ' can't be performed in read only transaction" ;
404
- const TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
405
390
issues.AddIssue (YqlIssue (pos, TIssuesIds::KIKIMR_BAD_OPERATION, message));
406
391
return {false , issues};
407
392
}
408
393
409
394
auto & currentOps = TableOperations[table];
410
- const bool currentModify = currentOps & KikimrModifyOps ();
395
+ bool currentModify = currentOps & KikimrModifyOps ();
411
396
if (currentModify) {
412
397
if (KikimrReadOps () & newOp) {
413
398
if (!EnableImmediateEffects) {
414
399
TString message = TStringBuilder () << " Data modifications previously made to table '" << table
415
400
<< " ' in current transaction won't be seen by operation: '"
416
401
<< newOp << " '" ;
417
- const TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
418
402
auto newIssue = AddDmlIssue (YqlIssue (pos, TIssuesIds::KIKIMR_READ_MODIFIED_TABLE, message));
419
403
issues.AddIssue (newIssue);
420
404
return {false , issues};
@@ -423,11 +407,10 @@ class TKikimrTransactionContextBase : public TThrRefBase {
423
407
HasUncommittedChangesRead = true ;
424
408
}
425
409
426
- if ((* info) ->GetHasIndexTables ()) {
410
+ if (info->GetHasIndexTables ()) {
427
411
if (!EnableImmediateEffects) {
428
412
TString message = TStringBuilder ()
429
413
<< " Multiple modification of table with secondary indexes is not supported yet" ;
430
- const TPosition pos (op.GetPosition ().GetColumn (), op.GetPosition ().GetRow ());
431
414
issues.AddIssue (YqlIssue (pos, TIssuesIds::KIKIMR_BAD_OPERATION, message));
432
415
return {false , issues};
433
416
}
@@ -445,9 +428,9 @@ class TKikimrTransactionContextBase : public TThrRefBase {
445
428
virtual ~TKikimrTransactionContextBase () = default ;
446
429
447
430
public:
431
+ THashMap<TString, TYdbOperations> TableOperations;
448
432
bool HasUncommittedChangesRead = false ;
449
433
const bool EnableImmediateEffects;
450
- THashMap<TString, TYdbOperations> TableOperations;
451
434
THashMap<TKikimrPathId, TString> TableByIdMap;
452
435
TMaybe<NKikimrKqp::EIsolationLevel> EffectiveIsolationLevel;
453
436
THashMap<TString, TString> TempTables;
0 commit comments