[SERVER-43575] Duplicate index because of deprecation of background Created: 23/Sep/19  Updated: 27/Oct/23  Resolved: 24/Sep/19

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Ben Rotz Assignee: Carl Champain (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-33149 createIndexes fails to report an erro... Closed
Operating System: ALL
Steps To Reproduce:

Example: runing db.test.createIndex({'a.b': 1}, {background: true});

Index existing in 4.0

 

{
  "v" : 2,
  "key" : {
    "a.b" : NumberLong(1)
  },
  "name" : "a_b_1",
  "ns" : "test.test"
},

Running db.test.createIndex({'a.b': 1}, {background: true}); is valid, and produces "all indexes already exist"

 

Same index, running db.test.createIndex({'a.b': 1}, {background: true});  in mongo 4.2 produces "Index with name: a.b_1 already exists with a different name"

 

Note the name using a period instead of an underscore

Participants:

 Description   

After upgrading to mongo 4.2 and running an "install" script on an application, I started getting some errors in regards to "Index with name: INDEX_NAME already exists with a different name"

The problem appears to be that related to index names (at some point in mongo's past, automatic index naming used an underscore to delineate field names, for example "a_b_1" instead of "a.b_1" for an index created on {'a.b': 1} and the background flag.

 

This isn't a big deal to me, I will just manually recreate indexes, but I did think it was a problem worth mentioning in case it ties to something else.

 

 

 



 Comments   
Comment by Carl Champain (Inactive) [ 24/Sep/19 ]

Hi ben@ethika.com,

Thanks for providing more details.

I was able to successfully recreate your example. As you pointed out, this error is returned when an index is not created because another index already exists with the same keys but with a different name; this is an intended change brought by SERVER-33149.

I will close this ticket as this is not a bug.

Kind regards,
Carl

Comment by Ben Rotz [ 23/Sep/19 ]

I see this has nothing to do with "background", it's actually just throwing an error when the name is different now (it did not use to do this).

The following also produce the same outcome:

db.test.createIndex({'a.b': 1}, {name: 'a_b_1'});
db.test.createIndex({'a.b': 1});

My apologies for making it out to seem like background was the culprit, it is not. It is a change in how mongo errors out when creating the same index with a different name vs. just having a note. I didn't see this behavior documented anywhere, but it probably is somewhere I just haven't looked at yet.

Comment by Ben Rotz [ 23/Sep/19 ]

If I run the following two commands in sequence:

db.test.createIndex({'a.b': 1}, {name: 'a_b_1', background: true});
db.test.createIndex({'a.b': 1}, {background: true});

4.0.12 gives me 

all indexes already exist

 

 

4.2 gives me

Index with name: a.b_1 already exists with a different name

 

 

Comment by Carl Champain (Inactive) [ 23/Sep/19 ]

Hi ben@ethika.com,

Thanks for the report.

I've followed your example, but if I run

db.test.createIndex({'a.b':1}, {background: true})

I get "all indexes already exist" in both cases.

Plus, the output of

db.test.getIndexes()

is the same for 4.0 and 4.2:

	{
		"v" : 2,
		"key" : {
			"a.b" : 1
		},
		"name" : "a.b_1",
		"ns" : "test.test",
		"background" : true
	}

It seems that you are running into this problem because you have old indexes - ones that use an underscore to define field names - but your example mentions 4.0 and I wasn't able to see this behavior.
Could you please clarify what you think is a bug?

Kind regards,
Carl

Generated at Thu Feb 08 05:03:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.