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)



Counter example of upper semicontinuity of global fiber dimension on the source
Let $X = (\mathbb{A}^2 \setminus \{x = 0\}) \coprod \mathbb{A}^1$, let $Y = \mathbb{A}^1$, and let $f$ be projection onto the first coordinate on the first component and the identity on the second. Then every point of $X$ lives in a one-dimensional fiber except the origin of the second component.


