We know that if $f : X\to Y$ is a morphism between two affine varieties over an algebraically closed field $k$, then the function that assigns to each point of $X$ the dimension of the fiber it belongs to is upper semicontinuous on $X$.

Does anyone know of a simple counterexample when $X$ is not irreducible (but remains an algebraic set over $k$, i.e a finitely generated $k$-algebra) to the global statement?

Edit: to avoid ambiguity I am looking for a counterexample in case $X$ is not irreducible when the dimension of the fibers is measured globally, i.e. $n\geq 0$, the set of $x\in X$ such that $\dim(f^{-1}(f(x) ) ) \geq n$ is closed in $X$.

Edit2: in his comments @dorebell linked an answer here https://mathoverflow.net/a/184925/3333 where a counterexample to the upper semicontinuity of global dimension on the source is given with $X$ and $Y$ affine and irreducible (it works even if the counterexample is explained looking at the dimension of fibers from the target)

11more comments