// IsErrorDuplicateViolateUniqueConstraint check err is sql error "duplicate key value violates unique constraint"
179499
func IsErrorDuplicateViolateUniqueConstraint(err error) bool {
	if ErrorDuplicateViolateUniqueConstraint.Match(err) {
		return true
	}
	switch e := err.(type) {
	case nil:
		return false
	case *pq.Error:
		return e.Code == "23505"
	case *mysql.MySQLError:
		return e.Number == 1062
	default:
		return strings.Contains(err.Error(), "pq: duplicate key value violates unique constraint")
	}
}
880052
func checkDuplicateColumnName(indexColNames []*ast.IndexColName) error {
	colNames := make(map[string]struct{}, len(indexColNames))
	for _, indexColName := range indexColNames {
		name := indexColName.Column.Name
		if _, ok := colNames[name.L]; ok {
			return infoschema.ErrColumnExists.GenWithStackByArgs(name)
		}
		colNames[name.L] = struct{}{}
	}
	return nil
}
722277
func isZoneConstrainedError(err error) bool {
	switch err := errors.Cause(err).(type) {
	case *ec2.Error:
		switch err.Code {
		case "Unsupported", "InsufficientInstanceCapacity":
			// A big hammer, but we've now seen several different error messages
			// for constrained zones, and who knows how many more there might
			// be. If the message contains "Availability Zone", it's a fair
			// bet that it's constrained or otherwise unusable.
			return strings.Contains(err.Message, "Availability Zone")
		case "InvalidInput":
			// If the region has a default VPC, then we will receive an error
			// if the AZ does not have a default subnet. Until we have proper
			// support for networks, we'll skip over these.
			return strings.HasPrefix(err.Message, "No default subnet for availability zone")
		case "VolumeTypeNotAvailableInZone":
			return true
		}
	}
	return false
}
210958
func (r *historyRecord) IsDuplicate(other interface{}) bool {
	rother, ok := other.(*historyRecord)
	if !ok {
		return false
	}
	return r.TabletType == rother.TabletType && r.ServingState == rother.ServingState
}
1324077
func (f *Fn) IsNotDuplicate() bool {
	funcName := f.DLLFuncName()
	if uniqDllFuncName[funcName] == false {
		uniqDllFuncName[funcName] = true
		return true
	}
	return false
}
1090321
func UniqueConstraint(t *testing.T, repo grimoire.Repo) {
	extra1 := Extra{}
	extra2 := Extra{}
	repo.From(extras).Set("slug", "slug1").MustInsert(&extra1)
	repo.From(extras).Set("slug", "slug2").MustInsert(&extra2)

	t.Run("UniqueConstraint", func(t *testing.T) {
		// inserting
		err := repo.From(extras).Set("slug", extra1.Slug).Insert(nil)
		assertConstraint(t, err, errors.UniqueConstraint, "slug")

		// updating
		err = repo.From(extras).Find(extra2.ID).Set("slug", extra1.Slug).Update(nil)
		assertConstraint(t, err, errors.UniqueConstraint, "slug")
	})
}
305024
func IsConflictErr(err error) bool {
	if err == nil {
		return false
	}

	return strings.HasPrefix(err.Error(), "Duplicate primary key")
}
857654
func IsErrPUEnforcementFailed(err error) bool {
	switch t := err.(type) {
	case *Error:
		return t.reason == PUPolicyEnforcementFailed
	default:
		return false
	}
}
370629
func (e *entry) deduplicate() {
	e.mu.Lock()
	defer e.mu.Unlock()

	if len(e.values) <= 1 {
		return
	}
	e.values = e.values.Deduplicate()
}
634389
func FindDuplicateProcess(binary string) (*os.Process, int, error) {
	all, err := BinaryDuplicateProcessIDs(binary)
	if err != nil {
		return nil, 0, err
	}
	if len(all) > 0 {
		p, err := os.FindProcess(all[0])
		if err != nil {
			return nil, 0, err
		}
		return p, all[0], nil
	}
	return nil, 0, nil
}
1346891
func NewErrorCollection(dup ...DuplicatationOptions) *ErrorCollection {
	ec := &ErrorCollection{}
	ec.Errors = []error{}
	ec.Formatter = DefaultErrorFormatter
	if len(dup) != 0 {
		ec.DuplicatationOptions = dup[0]
	}
	return ec
}
996957
func (b *BlockedEvals) GetDuplicates(timeout time.Duration) []*structs.Evaluation {
	var timeoutTimer *time.Timer
	var timeoutCh <-chan time.Time
SCAN:
	b.l.Lock()
	if len(b.duplicates) != 0 {
		dups := b.duplicates
		b.duplicates = nil
		b.l.Unlock()
		return dups
	}

	// Capture chans inside the lock to prevent a race with them getting
	// reset in Flush
	dupCh := b.duplicateCh
	stopCh := b.stopCh
	b.l.Unlock()

	// Create the timer
	if timeoutTimer == nil && timeout != 0 {
		timeoutTimer = time.NewTimer(timeout)
		timeoutCh = timeoutTimer.C
		defer timeoutTimer.Stop()
	}

	select {
	case <-stopCh:
		return nil
	case <-timeoutCh:
		return nil
	case <-dupCh:
		goto SCAN
	}
}
677982
func (adapter *PostgresAdapter) ErrorEquals(err error, sqlErrorType types.SQLErrorType) bool {
	if err, ok := err.(*pq.Error); ok {
		switch sqlErrorType {
		case types.SQLErrorTypeGeneric:
			return true
		case types.SQLErrorTypeDuplicatedColumn:
			return err.Code == "42701"
		case types.SQLErrorTypeDuplicatedTable:
			return err.Code == "42P07"
		case types.SQLErrorTypeDuplicatedSchema:
			return err.Code == "42P06"
		case types.SQLErrorTypeUndefinedTable:
			return err.Code == "42P01"
		case types.SQLErrorTypeUndefinedColumn:
			return err.Code == "42703"
		case types.SQLErrorTypeInvalidType:
			return err.Code == "42704"
		}
	}

	return false
}
42640
func (o *outerJoinEliminator) isInnerJoinKeysContainUniqueKey(innerPlan LogicalPlan, joinKeys *expression.Schema) (bool, error) {
	for _, keyInfo := range innerPlan.Schema().Keys {
		joinKeysContainKeyInfo := true
		for _, col := range keyInfo {
			columnName := &ast.ColumnName{Schema: col.DBName, Table: col.TblName, Name: col.ColName}
			c, err := joinKeys.FindColumn(columnName)
			if err != nil {
				return false, err
			}
			if c == nil {
				joinKeysContainKeyInfo = false
				break
			}
		}
		if joinKeysContainKeyInfo {
			return true, nil
		}
	}
	return false, nil
}
594044
func Duplicate(field *Path, value interface{}) *Error {
	return &Error{ErrorTypeDuplicate, field.String(), value, ""}
}
182809
func IsVersionInconsistentError(e interface{}) bool {
	value := e
	// In case of a wrapped error, check the cause first.
	cause := errors.Cause(e.(error))
	if cause != nil {
		value = cause
	}
	_, ok := value.(*versionInconsistentError)
	return ok
}
65027
func NewRecoverableError(e error, recoverable bool) error {
	if e == nil {
		return nil
	}

	return &RecoverableError{
		Err:         e.Error(),
		Recoverable: recoverable,
	}
}