Repository: milvus-io/milvus
File: internal/querycoordv2/task/utils.go (Go)

Code before:

	// Apply collection-level warmup to regular fields
	for _, field := range schema.GetFields() {
		// field-level warmup setting has higher priority, skip if field already has warmup setting
		if common.FieldHasWarmupKey(schema, field.GetFieldID()) {
			continue
		}

		isVector := typeutil.IsVectorType(field.GetDataType())
		if isVector && vectorFieldExist {
			field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
				Key:   common.WarmupKey,
				Value: vectorFieldWarmup,
			})
		} else if !isVector && scalarFieldExist {
			field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
				Key:   common.WarmupKey,
				Value: scalarFieldWarmup,
			})
		} else if autoWarmup && !isVector {
			// autoWarmupForNonPKIsolationCollection fallback: force sync warmup for scalar fields (not vector fields)
			field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
				Key:   common.WarmupKey,
				Value: common.WarmupSync,
			})
		}
	}

	// Apply warmup to struct array fields and their nested fields
	for _, structField := range schema.GetStructArrayFields() {
		// Get struct field's warmup setting
		structFieldWarmup, structHasWarmup := common.GetWarmupPolicy(structField.GetTypeParams()...)

		// Apply warmup setting to fields inside struct
		for _, field := range structField.GetFields() {
			// Skip if field already has warmup setting
			if common.FieldHasWarmupKey(schema, field.GetFieldID()) {
				continue
			}

			// Priority: struct field setting > collection setting > autoWarmupForNonPKIsolationCollection
			if structHasWarmup {
				field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
					Key:   common.WarmupKey,
					Value: structFieldWarmup,
				})
			} else {
				isVector := typeutil.IsVectorType(field.GetDataType())
				if isVector && vectorFieldExist {
					field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
						Key:   common.WarmupKey,

Review comment (performance):
The asymmetry between `autoWarmup && \!isVector` here (scalar fields only) vs `autoWarmup` in `applyIndexWarmupSetting` (all indexes) is intentional but not obvious. Worth a one-line comment: vector field raw data is excluded due to large size, while vector indexes are included because they are critical for query latency.

Code after:
	scalarFieldWarmup, scalarFieldExist := common.GetWarmupPolicyByKey(common.WarmupScalarFieldKey, collectionProperties...)
	vectorFieldWarmup, vectorFieldExist := common.GetWarmupPolicyByKey(common.WarmupVectorFieldKey, collectionProperties...)
	autoWarmup := autoWarmupForNonPKIsolationCollection(collectionProperties)

	// Apply collection-level warmup to regular fields
	for _, field := range schema.GetFields() {
		// field-level warmup setting has higher priority, skip if field already has warmup setting
		if common.FieldHasWarmupKey(schema, field.GetFieldID()) {
			continue
		}

		isVector := typeutil.IsVectorType(field.GetDataType())
		if isVector && vectorFieldExist {
			field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
				Key:   common.WarmupKey,
				Value: vectorFieldWarmup,
			})
		} else if !isVector && scalarFieldExist {
			field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
				Key:   common.WarmupKey,
				Value: scalarFieldWarmup,
			})
		} else if autoWarmup && !isVector {
			// autoWarmupForNonPKIsolationCollection fallback: force sync warmup for scalar fields (not vector fields)
			// vector fields are excluded from autowarmup due to its large size
			field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
				Key:   common.WarmupKey,
				Value: common.WarmupSync,
			})
		}
	}

	// Apply warmup to struct array fields and their nested fields
	for _, structField := range schema.GetStructArrayFields() {
		// Get struct field's warmup setting
		structFieldWarmup, structHasWarmup := common.GetWarmupPolicy(structField.GetTypeParams()...)

		// Apply warmup setting to fields inside struct
		for _, field := range structField.GetFields() {
			// Skip if field already has warmup setting
			if common.FieldHasWarmupKey(schema, field.GetFieldID()) {
				continue
			}

			// Priority: struct field setting > collection setting > autoWarmupForNonPKIsolationCollection
			if structHasWarmup {
				field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
					Key:   common.WarmupKey,
					Value: structFieldWarmup,
				})
			} else {