// filterOnExistence removes rows based on the existence of the fully qualified
// triple after the biding of the clause.
19129
func (p *queryPlan) filterOnExistence(ctx context.Context, cls *semantic.GraphClause, lo *storage.LookupOptions) error {
	data := p.tbl.Rows()
	p.tbl.Truncate()
	var (
		gErr error
		mu   sync.RWMutex
		wg   sync.WaitGroup
	)
	for _, tmp := range data {
		mu.RLock()
		if gErr != nil {
			// Try to stop early if an error occurred and we are still ussuing requests.
			mu.RUnlock()
			break
		}
		mu.RUnlock()
		wg.Add(1)
		go func(r table.Row, cls semantic.GraphClause) {
			defer wg.Done()
			sbj, prd, obj := cls.S, cls.P, cls.O
			// Attempt to rebind the subject.
			if sbj == nil && p.tbl.HasBinding(cls.SBinding) {
				v, ok := r[cls.SBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SBinding)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a node, got %+v instead", cls.SBinding, v)
					mu.Unlock()
					return
				}
				sbj = v.N
			}
			if sbj == nil && p.tbl.HasBinding(cls.SAlias) {
				v, ok := r[cls.SAlias]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a node, got %+v instead", cls.SAlias, v)
					mu.Unlock()
					return
				}
				sbj = v.N
			}
			// Attempt to rebind the predicate.
			if prd == nil && p.tbl.HasBinding(cls.PBinding) {
				v, ok := r[cls.PBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.PBinding)
					mu.Unlock()
					return
				}
				if v.P == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a predicate, got %+v instead", cls.PBinding, v)
					mu.Unlock()
					return
				}
				prd = v.P
			}
			if prd == nil && p.tbl.HasBinding(cls.PAlias) {
				v, ok := r[cls.PAlias]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a predicate, got %+v instead", cls.SAlias, v)
					mu.Unlock()
					return
				}
				prd = v.P
			}
			// Attempt to rebind the object.
			if obj == nil && p.tbl.HasBinding(cls.OBinding) {
				v, ok := r[cls.OBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.OBinding)
					mu.Unlock()
					return
				}
				co, err := cellToObject(v)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
				}
				obj = co
			}
			if obj == nil && p.tbl.HasBinding(cls.OAlias) {
				v, ok := r[cls.OAlias]
				if !ok {
					mu.Unlock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.OAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a object, got %+v instead", cls.OAlias, v)
					mu.Unlock()
					return
				}
				co, err := cellToObject(v)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				obj = co
			}
			// Attempt to filter.
			if sbj == nil || prd == nil || obj == nil {
				mu.Lock()
				gErr = fmt.Errorf("failed to fully specify clause %v for row %+v", cls, r)
				mu.Unlock()
				return
			}
			exist := false
			for _, g := range p.stm.InputGraphs() {
				t, err := triple.New(sbj, prd, obj)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				b, err := g.Exist(ctx, t)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				exist = exist || b
				if exist {
					break
				}
			}
			if exist {
				p.tbl.AddRow(r)
			}
		}(tmp, *cls)
	}
	wg.Wait()
	return gErr
}
1196190
func (api *SubnetAPI) FilterBy(key string, value interface{}) *SubnetAPI {
	api.filterBy(key, value, false)
	return api
}
592857
func (s *InputTemplate) SetFilterEnable(v string) *InputTemplate {
	s.FilterEnable = &v
	return s
}
104626
func FilterError(v interface{}) interface{} {
	if err, ok := v.(error); ok {
		return err.Error()
	}
	return v
}
1136838
func (s *TermvectorsService) Filter(filter *TermvectorsFilterSettings) *TermvectorsService {
	s.filter = filter
	return s
}
673867
func (o querySet) Filter(expr string, args ...interface{}) QuerySeter {
	if o.cond == nil {
		o.cond = NewCondition()
	}
	o.cond = o.cond.And(expr, args...)
	return &o
}
481715
func (l *limit) PushFilter(_ *primitiveBuilder, _ sqlparser.Expr, whereType string, _ builder) error {
	panic("BUG: unreachable")
}
136449
func (api *LoadBalancerAPI) SetFilterBy(key string, value interface{}) {
	api.filterBy(key, value, false)
}
510914
func (b *BoolQueryBuilder) Filter() *FilterQueryBuilder {
	if b.filterQueryBuilder == nil {
		b.filterQueryBuilder = NewFilterQueryBuilder()
	}
	return b.filterQueryBuilder
}
420806
func (fn FilterFunc) Filter(rels []*rspb.Release) (rets []*rspb.Release) {
	for _, rel := range rels {
		if fn.Check(rel) {
			rets = append(rets, rel)
		}
	}
	return
}
1018618
func (api *ProxyLBAPI) SetFilterBy(key string, value interface{}) {
	api.filterBy(key, value, false)
}
552577
func (api *BridgeAPI) FilterBy(key string, value interface{}) *BridgeAPI {
	api.filterBy(key, value, false)
	return api
}
1084592
func (service *BaseService) RemoveFilterByIndex(index int) Service {
	service.filterManager.RemoveFilterByIndex(index)
	return service
}
758190
func (client *BaseClient) RemoveFilter(filter ...Filter) Client {
	client.filterManager.RemoveFilter(filter...)
	return client
}
232098
func (api *IconAPI) FilterBy(key string, value interface{}) *IconAPI {
	api.filterBy(key, value, false)
	return api
}
499594
func (s *Input) SetFilterEnable(v string) *Input {
	s.FilterEnable = &v
	return s
}
843997
func (api *DatabaseAPI) SetFilterBy(key string, value interface{}) {
	api.filterBy(key, value, false)
}