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