It is an example of conditional sentence type 2. Type 2 sentences are used when it is unlikely that the condition will be fulfilled. It is formed like this :
"If" + [simple past] , "would" + [ verb ]
I thought I'd buy that apartment if I had a million dollars. (But it seems like money is tight, the apartment is way too expensive thus I can not afford it.)
In the above sentence the condition is at the back of the sentence so no comma is used.
In order to indicate that it is impossible for condition to be fulfilled because the possibility has already passed,we use conditional sentence type three.It is formed like this:
"if" + [Past Perfect], "would have" + [Past Participle]
The type 3 conditional refers to an impossible condition (unfulfilled event) in the past and its probable result in the past. These sentences are truly hypothetical and unreal, because it is now too late for the condition or its result to exist. There is always some implication of regret with type 3 conditional sentences. The reality is the opposite of, or contrary to, what the sentence expresses. In type 3 conditional sentences, the time is the past and the situation is hypothetical.
If I had worked harder I would have passed the exam. (But I didn't work hard, and I didn't pass the exam.)
If I had known you were coming I would have baked a cake. (But I didn't know and I didn't bake a cake.)
I thought I would have bought that apartment if I had had a million dollars.( But I was wrong and the possibility of buying that apartment has already passed. )
Both would and had can be contracted to 'd, which can be confusing if you are not confident with type 3 conditional sentences. Remember 2 rules:
would never appears in the if-clause so if 'd appears in the if clause, it must be abbreviating had.
had never appears before have so if 'd appears on a pronoun just before have, it must be abbreviating would.
For more details, please follow the link below: