TITLE: Is the restriction of a flat morphism flat?
QUESTION [5 upvotes]: Let $X$ be a projective scheme, $X_1, X_2$ be closed subschemes of $X$. Let $f:X \to S$ be a flat morphism for some scheme $S$. Denote by $i_1$ and $i_2$ the natural inclusion maps from $X_1$ and $X_2$, respectively to $X$. Assume that the composition maps $f \circ i_1$ and $f \circ i_2$ are flat. Is it then true that the fiber product $X_1 \times_X X_2$ is flat over $S$ under the natural maps $f \circ i_1 \circ pr_1$ or $f \circ i_2 \circ pr_2$, where $pr_i$ is the natural projection morphism from $X_1 \times_X X_2$ onto its $i$-th coordinate?

REPLY [2 votes]: In the spirit of Georges's philosophy of recording useful (counter)examples, let me offer another:
Consider the projection $X = \mathbb A^2 \to S = \mathbb A^1$ given by $(x,y) \mapsto x$.
Now let $X_1$ be the line $y = 0$ and $X_2$ be the line $x  + y = 0$.  Both map
isomorphically to $\mathbb A^1$ (and an isomorphism is flat!).  However there
intersection is the single point $(0,0)$, which does not map flatly to $\mathbb A^1$.
(Note: as with Georges's answer, my varieties are not projective, because it is easier to write formulas in the affine setting.  It is an exercise to "complete" the above example to give an analogous example with projective varieties.)

General remark: As Georges pointed out in his answer, and as I used above,
the fibre product over $X$ of two closed subschemes of $X$ is just their (scheme-theoretic) intersection.  So the map you are asking about, namely $X_1\times_X X_2 \to S$, factors as the closed immersion $X_1\times X_2 \to X_1$, followed by the flat map $X_1 \to S$.  Since closed immersions are never flat unless they are isomorphisms, there is no reason at all to think that the answer to your question would be yes, and of course it was easy for Georges and me to come up with counterexamples, just by thinking of examples of non-trivial (and hence non-flat) closed immersions.