An inequality about the dimension of fiber I am working on Problem 11.4.A of Vakil's notes:

Let $X$ and $Y$ be two locally noetherian schemes, $\pi:X \to Y$ is a morphism, and $\pi(p)=q$. Then prove:
  $$\operatorname{codim}_Xp \leq \operatorname{codim}_Yq+\operatorname{codim}_{\pi^{-1}(q)}p.$$

There are morphisms of stalks:
$O_{Y,q} \to O_{X,p}$ and $O_{X,p} \to O_{\pi^{-1}(q),p}$ 
How can I use a set of parameters which cut out the maximal ideal in $O_{Y,q}$ and a set of parameters which cut out the maximal ideal in $O_{\pi^{-1}(q),p}$ to get a set of equations that cut out the maximal ideal in $O_{X,p}$? There is no problem to go from $O_{Y,q}$ to $O_{X,p}$, but how can I lift elements from $O_{\pi^{-1}(q),p}$ to $O_{X,p}$?
 A: $\DeclareMathOperator{\Spec}{Spec}\newcommand{\frakq}{\mathfrak{q}}\newcommand{\frakp}{\mathfrak{p}}\newcommand{\inv}{^{-1}}\newcommand{\frakm}{\mathfrak{m}}\newcommand{\frakn}{\mathfrak{n}}$


*

*Reduce to the case $X = \Spec A$ and $Y = \Spec B$ are both affine. (If you think more carefully, it can be further reduced to the case where $B$ is integral and $q$ is a closed point, but that is not necessary.)

*In this case, the problem is:

Suppose $\varphi: B \to A$ is a ring homomorphism and $\frakp \subseteq A$ 
  and $\frakq\subseteq B$ are prime ideals such that
  $\varphi\inv(\frakp) = \frakq$. Then we have
  $$ \dim A_\frakp \leq \dim B_\frakq + \dim \big(A \otimes_B \kappa(\frakq)\big)_{\frakp'},$$
  where $\kappa(\frakq) = B_\frakq/\frakq B_\frakq$ is the residue field at $\frakq$
  and $\frakp' \subseteq A \otimes_B \kappa(\frakq)$ is the image of $\frakp \subseteq A$ in $A \otimes_B \kappa(\frakq)$.


*Important observation:
$$\big(A \otimes_B \kappa(\frakq))_{\frakp'} = A_\frakp/\frakq A_\frakp.$$
(This part is what Hoot commented as "It's really a tricky exercise in commuting localizations and quotients.")

*Now the problem reduces to the following algebraic result.

Suppose that $(B, \frakm) \to (A, \frakn)$ is a local homomorphism
  of Noetherian local rings, then
  $$ \dim A \leq \dim B + \dim A/\frakm A.$$


*To prove 4., using the hint in [Vakil], find a system of parameters for $B$ and a system for $A/\frakm A$. Say,
\begin{align*}
\sqrt{b_1, \ldots, b_d} & = \frakm,\\
\sqrt{\bar a_1, \ldots, \bar a_e} &= \frakn / \frakm A
\end{align*}
Take any lifts $a_1, \ldots, a_e \in A$ of $\bar a_1, \ldots, \bar a_e \in A/\frakm A$. Using the fact that these ideals are all finitely generated, we can first conclude that for a sufficiently large $\ell \gg 0$,
$$
\frakn^\ell \subseteq (a_1, \ldots, a_e) + \frakm A,
$$
then for a sufficiently large $r \gg \ell$,
$$
\frakn^r \subseteq (a_1, \ldots, a_e, b_1, \ldots, b_d).
$$
So  $\frakn = \sqrt{ (a_1, \ldots, a_e, b_1, \ldots, b_d)}$． Then use Krull's Height Theorem.

*Done．

The above approach is pure algebraic, I hope someone could provide a ''geometric'' proof. 
A: I am grateful for Hoot's hint. This seems to be the key for the exercise! Let me try to "contribute" a bit by providing a pretty much same proof with a different ending. I don't claim any credit, but I hope this is correct.
As in natural stupidity's answer, Hoot's hint reduces the problem to show that: given a local map $\phi : (B, \mathfrak{q}) \rightarrow (A, \mathfrak{p})$ of Noetherian local rings, we have $\dim(A) \leq \dim(B) + \dim(A/\mathfrak{q}A).$
Since $(A/\mathfrak{q}A, \mathfrak{p}/\mathfrak{q}A)$ is a Noetherian local ring, we may write $V_{A/\mathfrak{q}A}(\bar{a}_{1}, \dots, \bar{a}_{m}) = \{\mathfrak{p}/\mathfrak{q}A\},$ where $m = \dim(A/\mathfrak{q}A) < \infty.$ Consider the homeomophic embedding $\text{Spec}(A/\mathfrak{q}A) \hookrightarrow \text{Spec}(A)$ whose image is $V_{A}(\mathfrak{q}A).$ Under this map, the image of $V_{A/\mathfrak{q}A}(\bar{a}_{1}, \dots, \bar{a}_{m}) = \{\mathfrak{p}/\mathfrak{q}A\}$ is $V_{A}(a_{1}, \dots, a_{m}, \mathfrak{q}A) = \{\mathfrak{p}\}.$ This is because, for any ideals $I \subset J$ in $A,$ the closed subset $V_{A/I}(J/I)$ mapsto $V_{A}(J)$ under the homeomorphic embedding $\text{Spec}(A/I) \hookrightarrow \text{Spec}(A)$, which is essentially because $A/J \simeq (A/J)/(I/J)$.
Since $(B, \mathfrak{q})$ is a Noetherian local ring, so we may write $V_{B}(b_{1}, \dots, b_{n}) = \{\mathfrak{q}\},$ where $n = \dim(B) < \infty$. Under the map $\text{Spec}(A) \rightarrow \text{Spec}(A)$ induced by $\phi : B \rightarrow A,$ we note that $V_{B}(b_{1}, \dots, b_{n}) = \{\mathfrak{q}\}$ pulls back to $V_{A}(\phi(b_{1}), \dots, \phi(b_{n})) = V_{A}(\mathfrak{q}A)$.
Thus, we have $\{\mathfrak{p}\} = V_{A}(a_{1}, \dots, a_{m}, \mathfrak{q}A) = V_{A}(a_{1}, \dots, a_{m}) \cap V_{A}(\mathfrak{q}A) = V_{A}(a_{1}, \dots, a_{m}, \mathfrak{q}A) = V_{A}(a_{1}, \dots, a_{m}) \cap V_{A}(\phi(b_{1}), \dots, \phi(b_{n})) = V_{A}(a_{1}, \dots, a_{m}, \phi(b_{1}), \dots, \phi(b_{m}))$. Hence, by Krull's height theorem, we have $\dim(A) = \text{ht}(\mathfrak{p}) \leq m + n = \dim(B) + \dim(\mathfrak{p}/\mathfrak{q}A),$ as desired.
A: Considered the diagram:
$$
\require{AMScd}
\begin{CD}
\pi^{-1}(q)=X\times_YSpec\,\kappa(q)@> >> Spec\,\kappa(q)\\
@ViVV @VVV\\
X @>>\pi> Y
\end{CD}
$$
where $\kappa(q)$ is the residue field of the point $q$, and $i:\pi^{-1}(q)\hookrightarrow X$ is the inclusion morphism; using the associated sheaves, one has the sequences of rings:
$$
\forall U\subseteq Y\,\text{open},\,q\in Y,\begin{CD}
\mathcal{O}_Y(U) @>\pi^{\sharp}(U)>> \mathcal{O}_X(\pi^{-1}(U)) @>i^{\sharp}(\pi^{-1}(U))>> \mathcal{O}_{\pi^{-1}(q)}((\pi\circ i)^{-1}(U))\\
@VVV @VVV @VVV\\
\mathcal{O}_{Y,q} @>\pi^{\sharp}_p>> \mathcal{O}_{X,p} @>i^{\sharp}_p>> \mathcal{O}_{\pi^{-1}(q),p} @>>> 0\\
& @VVV @VVV\\
& & \kappa(p) @>\widetilde{i^{\sharp}_p}>> \kappa(p)
\end{CD}
$$
where the central row is right exact.
Because $\pi^{-1}(q)$ is a subscheme of $X$ then $\widetilde{i^{\sharp}_p}$ is an automorphism of the residue field $\kappa(p)$ of $p$, and it turns out that $i^{\sharp}_p$ is a surjective morphism.
By hypotehsis of locally Noetherianess, whether the local Noetherian rings are regular then the Krull dimensions of these local rings are equal to the dimensions of the relevant cotangent spaces; in other words:
$$
\mathrm{codim}_Xp=\dim_{Krull}\mathcal{O}_{X,p}=\dim T_{X,p},\\
\mathrm{codim}_Yq=\dim_{Krull}\mathcal{O}_{Y,q}=\dim T_{Y,q},\\
\mathrm{codim}_{\pi^{-1}(q)}p=\dim_{Krull}\mathcal{O}_{\pi^{-1}(q),p}=\dim T_{\pi^{-1}(q),p};
$$
by previous right exact sequence of local rings, because $i^{\sharp}_p$ and $\pi^{\sharp}_p$ are morphism of local rings:
$$
\dim T_{X,p}\leq\dim T_{Y,q}+\dim T_{\pi^{-1}(q),p}
$$
that is the claim.
Otherwise, whether some ring is not regular, you can consider the systems of parameters of the previous Noetherain local rings and so you can prove the claim in general!
