We know that if $f : X\to Y$ is a morphism between two irreducible 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 anymore (but remains an algebraic set over $k$, i.e a finitely generated $k$-algebra) ?

Edit : to avoid ambiguity about the definition of upper semicontinuity, it means here that for all $n\geq 0$, the set of $x\in X$ such that $\dim(f^{-1}(f(x) ) ) \geq n$ is closed in $X$.

It seems to me it is not so obvious to find a counterexample, since in fact the set of $x\in X$ such that the dimension of the irreducible component of $f^{-1}(f(x) )$ in $X$ that contains $x$ is $\geq n$ is always closed even when $X$ is not irreducible.