@@ -279,7 +279,7 @@ func (h *Hub) GetSchema(remoteSchema string, localSchema string) (*proto.Schema,
279279}
280280
281281// GetIterator creates and returns an iterator
282- func (h * Hub ) GetIterator (columns []string , quals * proto.Quals , limit int64 , opts types.Options ) (Iterator , error ) {
282+ func (h * Hub ) GetIterator (columns []string , quals * proto.Quals , unhandledRestrictions int , limit int64 , opts types.Options ) (Iterator , error ) {
283283 logging .LogTime ("GetIterator start" )
284284 qualMap , err := h .buildQualMap (quals )
285285 connectionName := opts ["connection" ]
@@ -296,10 +296,10 @@ func (h *Hub) GetIterator(columns []string, quals *proto.Quals, limit int64, opt
296296 var iterator Iterator
297297 // if this is a legacy aggregator connection, create a group iterator
298298 if h .IsLegacyAggregatorConnection (connectionName ) {
299- iterator , err = newLegacyGroupIterator (connectionName , table , qualMap , columns , limit , h , scanTraceCtx )
299+ iterator , err = newLegacyGroupIterator (connectionName , table , qualMap , unhandledRestrictions , columns , limit , h , scanTraceCtx )
300300 log .Printf ("[TRACE] Hub GetIterator() created aggregate iterator (%p)" , iterator )
301301 } else {
302- iterator , err = h .startScanForConnection (connectionName , table , qualMap , columns , limit , scanTraceCtx )
302+ iterator , err = h .startScanForConnection (connectionName , table , qualMap , unhandledRestrictions , columns , limit , scanTraceCtx )
303303 log .Printf ("[TRACE] Hub GetIterator() created iterator (%p)" , iterator )
304304 }
305305
@@ -473,7 +473,7 @@ func (h *Hub) traceContextForScan(table string, columns []string, limit int64, q
473473}
474474
475475// startScanForConnection starts a scan for a single connection, using a scanIterator or a legacyScanIterator
476- func (h * Hub ) startScanForConnection (connectionName string , table string , qualMap map [string ]* proto.Quals , columns []string , limit int64 , scanTraceCtx * telemetry.TraceCtx ) (_ Iterator , err error ) {
476+ func (h * Hub ) startScanForConnection (connectionName string , table string , qualMap map [string ]* proto.Quals , unhandledRestrictions int , columns []string , limit int64 , scanTraceCtx * telemetry.TraceCtx ) (_ Iterator , err error ) {
477477 defer func () {
478478 if err != nil {
479479 // close the span in case of errir
@@ -489,7 +489,7 @@ func (h *Hub) startScanForConnection(connectionName string, table string, qualMa
489489 }
490490 // if this is a legacy plugin, create legacy iterator
491491 if ! connectionPlugin .SupportedOperations .MultipleConnections {
492- return h .startScanForLegacyConnection (connectionName , table , qualMap , columns , limit , scanTraceCtx )
492+ return h .startScanForLegacyConnection (connectionName , table , qualMap , unhandledRestrictions , columns , limit , scanTraceCtx )
493493 }
494494
495495 // ok so this is a multi connection plugin, build list of connections,
@@ -506,7 +506,7 @@ func (h *Hub) startScanForConnection(connectionName string, table string, qualMa
506506 connectionNames = connectionConfig .GetResolveConnectionNames ()
507507 }
508508 // for each connection, determine whether to pushdown the limit
509- connectionLimitMap , err := h .buildConnectionLimitMap (table , qualMap , connectionNames , limit , connectionPlugin )
509+ connectionLimitMap , err := h .buildConnectionLimitMap (table , qualMap , unhandledRestrictions , connectionNames , limit , connectionPlugin )
510510 if err != nil {
511511 return nil , err
512512 }
@@ -524,7 +524,7 @@ func (h *Hub) startScanForConnection(connectionName string, table string, qualMa
524524 return iterator , nil
525525}
526526
527- func (h * Hub ) buildConnectionLimitMap (table string , qualMap map [string ]* proto.Quals , connectionNames []string , limit int64 , connectionPlugin * steampipeconfig.ConnectionPlugin ) (map [string ]int64 , error ) {
527+ func (h * Hub ) buildConnectionLimitMap (table string , qualMap map [string ]* proto.Quals , unhandledRestrictions int , connectionNames []string , limit int64 , connectionPlugin * steampipeconfig.ConnectionPlugin ) (map [string ]int64 , error ) {
528528 log .Printf ("[TRACE] buildConnectionLimitMap, table: '%s', %d %s, limit: %d" , table , len (connectionNames ), utils .Pluralize ("connection" , len (connectionNames )), limit )
529529
530530 connectionSchema , err := connectionPlugin .GetSchema (connectionNames [0 ])
@@ -538,7 +538,7 @@ func (h *Hub) buildConnectionLimitMap(table string, qualMap map[string]*proto.Qu
538538 // check once whether we should push down
539539 if limit != - 1 && schemaMode == plugin .SchemaModeStatic {
540540 log .Printf ("[TRACE] static schema - using same limit for all connections" )
541- if ! h .shouldPushdownLimit (table , qualMap , connectionSchema ) {
541+ if ! h .shouldPushdownLimit (table , qualMap , unhandledRestrictions , connectionSchema ) {
542542 limit = - 1
543543 }
544544 }
@@ -548,7 +548,7 @@ func (h *Hub) buildConnectionLimitMap(table string, qualMap map[string]*proto.Qu
548548 for _ , c := range connectionNames {
549549 connectionLimit := limit
550550 // if schema mode is dynamic, check whether we should push down for each connection
551- if schemaMode == plugin .SchemaModeDynamic && ! h .shouldPushdownLimit (table , qualMap , connectionSchema ) {
551+ if schemaMode == plugin .SchemaModeDynamic && ! h .shouldPushdownLimit (table , qualMap , unhandledRestrictions , connectionSchema ) {
552552 log .Printf ("[INFO] not pushing limit down for connection %s" , c )
553553 connectionLimit = - 1
554554 }
@@ -558,10 +558,10 @@ func (h *Hub) buildConnectionLimitMap(table string, qualMap map[string]*proto.Qu
558558 return connectionLimitMap , nil
559559}
560560
561- func (h * Hub ) startScanForLegacyConnection (connectionName string , table string , qualMap map [string ]* proto.Quals , columns []string , limit int64 , scanTraceCtx * telemetry.TraceCtx ) (_ Iterator , err error ) {
561+ func (h * Hub ) startScanForLegacyConnection (connectionName string , table string , qualMap map [string ]* proto.Quals , unhandledRestrictions int , columns []string , limit int64 , scanTraceCtx * telemetry.TraceCtx ) (_ Iterator , err error ) {
562562 // if this is an aggregate connection, create a group iterator
563563 if h .IsLegacyAggregatorConnection (connectionName ) {
564- return newLegacyGroupIterator (connectionName , table , qualMap , columns , limit , h , scanTraceCtx )
564+ return newLegacyGroupIterator (connectionName , table , qualMap , unhandledRestrictions , columns , limit , h , scanTraceCtx )
565565 }
566566
567567 connectionPlugin , err := h .getConnectionPlugin (connectionName )
@@ -576,7 +576,7 @@ func (h *Hub) startScanForLegacyConnection(connectionName string, table string,
576576 // determine whether to include the limit, based on the quals
577577 // we ONLY pushdown the limit is all quals have corresponding key columns,
578578 // and if the qual operator is supported by the key column
579- if limit != - 1 && ! h .shouldPushdownLimit (table , qualMap , connectionSchema ) {
579+ if limit != - 1 && ! h .shouldPushdownLimit (table , qualMap , unhandledRestrictions , connectionSchema ) {
580580 limit = - 1
581581 }
582582
@@ -602,7 +602,12 @@ func (h *Hub) startScanForLegacyConnection(connectionName string, table string,
602602// determine whether to include the limit, based on the quals
603603// we ONLY pushdown the limit if all quals have corresponding key columns,
604604// and if the qual operator is supported by the key column
605- func (h * Hub ) shouldPushdownLimit (table string , qualMap map [string ]* proto.Quals , connectionSchema * proto.Schema ) bool {
605+ func (h * Hub ) shouldPushdownLimit (table string , qualMap map [string ]* proto.Quals , unhandledRestrictions int , connectionSchema * proto.Schema ) bool {
606+ // if we have any unhandled restrictions, we CANNOT push limit down
607+ if unhandledRestrictions > 0 {
608+ return false
609+ }
610+
606611 // build a map of all key columns
607612 tableSchema , ok := connectionSchema .Schema [table ]
608613 if ! ok {
0 commit comments