@@ -772,8 +772,9 @@ type queryState struct {
772772 cache * posting.LocalCache
773773}
774774
775- func (qs * queryState ) helpProcessTask (
776- ctx context.Context , q * pb.Query , gid uint32 ) (* pb.Result , error ) {
775+ func (qs * queryState ) helpProcessTask (ctx context.Context , q * pb.Query , gid uint32 ) (
776+ * pb.Result , error ) {
777+
777778 span := otrace .FromContext (ctx )
778779 out := new (pb.Result )
779780 attr := q .Attr
@@ -854,8 +855,6 @@ func (qs *queryState) helpProcessTask(
854855 }
855856
856857 if srcFn .fnType == regexFn {
857- // Go through the indexkeys for the predicate and match them with
858- // the regex matcher.
859858 span .Annotate (nil , "handleRegexFunction" )
860859 if err := qs .handleRegexFunction (ctx , funcArgs {q , gid , srcFn , out }); err != nil {
861860 return nil , err
@@ -961,8 +960,18 @@ func (qs *queryState) handleRegexFunction(ctx context.Context, arg funcArgs) err
961960 // Here we determine the list of uids to match.
962961 switch {
963962 // If this is a filter eval, use the given uid list (good)
964- case arg .q .UidList != nil && len (arg .q .UidList .Uids ) != 0 :
965- uids = arg .q .UidList
963+ case arg .q .UidList != nil :
964+ // These UIDs are copied into arg.out.UidMatrix which is later updated while
965+ // processing the query. The below trick makes a copy of the list to avoid the
966+ // race conditions later. I (Aman) did a race condition tests to ensure that we
967+ // do not have more race condition in similar code in the rest of the file.
968+ // The race condition was found only here because in filter condition, even when
969+ // predicates do not have indexes, we allow regexp queries (for example, we do
970+ // not support eq/gt/lt/le in @filter, see #4077), and this was new code that
971+ // was added just to support the aforementioned case, the race condition is only
972+ // in this part of the code.
973+ uids = & pb.List {}
974+ uids .Uids = append (arg .q .UidList .Uids [:0 :0 ], arg .q .UidList .Uids ... )
966975
967976 // Prefer to use an index (fast)
968977 case useIndex :
0 commit comments