What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 138 Stack Exchange communities.

First of all, I should say that I think that this question does not belong on Meta.

StackOverflow URLs are inspirational to me, the way they are designed is very clever and they work really well but I can't seem to understand the logic being the IDs, here are some examples:


If you change the ID to ID++ (2121721) one could think it would fetch the next question. Wrong, instead you're redirect to another question whose ID seems to be totally unrelated (2121212):


Why does this happen? Is there some checksum algorithm on the IDs? Here is a sample trace:

2121720 -> exists
2121721 -> 2121212
2121213 -> exists
2121214 -> 2121155
2121156 -> exists
2121157 -> 2120884
2120885 -> exists
2120886 -> 2115014
2115015 -> 2114896 (what happened here?)
2114897 -> 2114799
2114800 -> 2114670 (what happened here?)
2114671 -> exists
2114672 -> 2110215
2110216 -> exists
2110217 -> 2106982
2106983 -> 2106955 (what happened here?)

The IDs seem to decrease. Can someone bring some light on this strange redirect behavior?

share|improve this question

migrated from stackoverflow.com Jan 23 '10 at 5:06

This question came from our site for professional and enthusiast programmers.

That notation is confusing. Does "foo -> exists" mean foo exists, or that foo redirects to an unnamed id which exists? –  Anonymous Jan 23 '10 at 2:21
this is surely a meta.stackoverflow.com question. –  Alex Brown Jan 23 '10 at 2:24
@Anonymous: Fixed, should be cleared now. –  Alix Axel Jan 23 '10 at 2:25
@Alex Brown: You think? I'm trying to understand how and why it acts this way, as in a programming-related question, not as a "I've a doubt about SO" question. –  Alix Axel Jan 23 '10 at 2:28
This seems more like a Meta question. –  cletus Jan 23 '10 at 2:36
@cletus & @Alex Brown: Sure, if you think so go ahead and close it. =) –  Alix Axel Jan 23 '10 at 2:46
How is this a meta question? Its programming related... –  Shawn Mclean Jan 23 '10 at 2:50
It's more of a SO question than a programming question, because you are asking something specific to this site rather than general to content management. –  Ether Jan 23 '10 at 3:31
@Ether: Still it has an insightful programming explanation. –  Alix Axel Jan 23 '10 at 3:51

2 Answers 2

up vote 12 down vote accepted

It looks to me like the IDs that redirect are actually IDs of answers - so when you put in 2121721, that ID actually belongs to an answer to the question with the ID 2121212. Notice how it redirects to one of the answers, not just to the question. The reason they decrease is that the answer was created after the question.

What this tells me is that the IDs are at least somewhat global. It may or may not mean everything is stored in the same table - though I wouldn't think so.

share|improve this answer
Oh! ID's of answers, that's smart! =) –  Alix Axel Jan 23 '10 at 2:30
Interestingly, the id of this question + 1 redirects to an answer that you have given to a completely different question! Freaky.. –  Mongus Pong Jan 23 '10 at 2:33
@Pongus Mung: Nice catch, freaky indeed. –  Alix Axel Jan 23 '10 at 2:45
Yeah, notice what happens when you click on "link" below the answer - it links to a separate id from the question! –  BlueRaja Jan 23 '10 at 3:33
I dunno, it might make sense to normalise out at least the text of questions and answers into the same table. –  Justin Jan 23 '10 at 12:00

Stack Overflow uses one table to hold both questions and answers. The ID is the primary key in the table called Posts. The ID is incremented each time a question or answer is posted.

So, yes, the ID and ID+1 for two posts would likely point to two entirely different questions.

You can read about the database schema in Understanding the Stack Overflow Database Schema.1

Posts Table

In StackOverflow, questions and answers are both considered posts. If a record has a null ParentId field, then it's a question. Otherwise, it's an answer, and to find the matching question, join the ParentId field up to Posts.Id.

  • Id - primary key, identity field from the original StackOverflow database.
  • Title - the title of the question. Answer titles will be null.
  • OwnerUserId - joins back to Users.Id. If OwnerUserId = -1, that's the community user, meaning it's a wiki question or answer.
  • AcceptedAnswerId - for questions, this points to the Post.Id of the officially accepted answer. This isn't necessarily the highest-voted answer, but the one the questioner accepted.

1Technically the schema is for the Stack Overflow Creative Commons Data Dump which is not a 100% mirror of the live database, but gives you a reasonable subset of the data.

share|improve this answer
+1, I would up vote this 10 times if I could just for the SQL Server Pedia link you provided! Do you know any similar website specific to MySQL? –  Alix Axel Jan 23 '10 at 3:26
@Alix Axel - Sorry, no. But maybe the folks over at meta would have a MySQL-specific reference (meta.stackoverflow.com). –  Robert Cartaino Jan 23 '10 at 4:21
The id of the user Community is -1 not 1. –  Andreas Bonini Jan 23 '10 at 12:25
The info at the SQL Server Pedia link might need to be updated. Among other things, we now have 3 post types. Though I don't know who is in charge of such a thing, though... –  Grace Note Jan 12 '11 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .