The first one is an example of what is called a mixed conditional.
The second sentence is the one traditionally taught in most coursebooks.
Contrary to popular belief, their are more than four conditional structures. Mario Rinvolucri, the EFL guru(?), argued that there were over 90 variations of conditional structures in his book Grammar Game
If I knew Mary was coming is in practice used for both present and past times.
If I knew Mary was coming, I would go ot the airport. (present time) If I knew Mary was coming, I would have gone to the the airport to welcome her. (past time)