@@ -372,10 +372,9 @@ static void set_external_engine_fail_reason(const LEX *lex,
372
372
reason != nullptr ) {
373
373
for (Table_ref *ref = lex->query_tables ; ref != nullptr ;
374
374
ref = ref->next_global ) {
375
- if (ref->table != nullptr && ref->table ->file != nullptr &&
376
- (ref->table ->file ->ht ->flags & HTON_SUPPORTS_EXTERNAL_SOURCE) != 0 &&
377
- ref->table ->s ->has_secondary_engine ()) {
378
- ref->table ->file ->set_external_table_offload_error (reason);
375
+ if (ref->is_external ()) {
376
+ ref->table ->get_primary_handler ()->set_external_table_offload_error (
377
+ reason);
379
378
break ;
380
379
}
381
380
}
@@ -385,10 +384,8 @@ static void set_external_engine_fail_reason(const LEX *lex,
385
384
static void external_engine_fail_reason (const LEX *lex) {
386
385
for (Table_ref *ref = lex->query_tables ; ref != nullptr ;
387
386
ref = ref->next_global ) {
388
- if (ref->table != nullptr && ref->table ->file != nullptr &&
389
- (ref->table ->file ->ht ->flags & HTON_SUPPORTS_EXTERNAL_SOURCE) != 0 &&
390
- ref->table ->s ->has_secondary_engine ()) {
391
- ref->table ->file ->external_table_offload_error ();
387
+ if (ref->is_external ()) {
388
+ ref->table ->get_primary_handler ()->external_table_offload_error ();
392
389
return ;
393
390
}
394
391
}
@@ -665,9 +662,7 @@ bool Sql_cmd_select::prepare_inner(THD *thd) {
665
662
666
663
static bool has_external_table (Table_ref *query_tables) {
667
664
for (Table_ref *ref = query_tables; ref != nullptr ; ref = ref->next_global ) {
668
- if (ref->table != nullptr && ref->table ->file != nullptr &&
669
- (ref->table ->file ->ht ->flags & HTON_SUPPORTS_EXTERNAL_SOURCE) != 0 &&
670
- ref->table ->s ->has_secondary_engine ()) {
665
+ if (ref->is_external ()) {
671
666
return true ;
672
667
}
673
668
}
@@ -684,8 +679,6 @@ bool Sql_cmd_dml::execute(THD *thd) {
684
679
bool statement_timer_armed = false ;
685
680
bool error_handler_active = false ;
686
681
687
- // flag to denote if the query refers to an external table
688
- bool is_external_table = false ;
689
682
// flag to determine if execution was not offloaded to the secondary engine
690
683
// and ended up in the external engine in which case we throw an error.
691
684
bool external_table_not_offloaded = false ;
@@ -747,18 +740,18 @@ bool Sql_cmd_dml::execute(THD *thd) {
747
740
}
748
741
}
749
742
750
- is_external_table = has_external_table (lex->query_tables );
751
- if (lex->thd -> variables . use_secondary_engine == SECONDARY_ENGINE_OFF &&
752
- is_external_table) {
753
- my_error (ER_SECONDARY_ENGINE_PLUGIN, MYF ( 0 ),
754
- " Query could not be offloaded to the secondary engine " ) ;
755
- external_table_not_offloaded = true ;
756
- goto err; // NOLINT
743
+ if (lex->thd -> variables . use_secondary_engine == SECONDARY_ENGINE_OFF) {
744
+ if (has_external_table ( lex->query_tables )) {
745
+ my_error (ER_SECONDARY_ENGINE_PLUGIN, MYF ( 0 ),
746
+ " Query could not be offloaded to the secondary engine " );
747
+ external_table_not_offloaded = true ;
748
+ goto err; // NOLINT
749
+ }
757
750
} else if ((thd->secondary_engine_optimization () ==
758
751
Secondary_engine_optimization::PRIMARY_ONLY &&
759
752
lex->thd ->variables .use_secondary_engine !=
760
753
SECONDARY_ENGINE_FORCED) &&
761
- is_external_table ) {
754
+ has_external_table (lex-> query_tables ) ) {
762
755
// throw the propagated error from the external engine in case there is an
763
756
// external table
764
757
external_engine_fail_reason (lex);
@@ -855,9 +848,10 @@ bool Sql_cmd_dml::execute(THD *thd) {
855
848
assert (thd->get_stmt_da () != nullptr );
856
849
// here we check if there is any table in an external engine to set the
857
850
// error there as well.
858
- if (is_external_table)
851
+ if (has_external_table (lex-> query_tables )) {
859
852
set_external_engine_fail_reason (lex,
860
853
thd->get_stmt_da ()->message_text ());
854
+ }
861
855
set_secondary_engine_fail_reason (lex,
862
856
thd->get_stmt_da ()->message_text ());
863
857
}
0 commit comments