TITLE: Counter example of upper semicontinuity of global fiber dimension on the source
QUESTION [6 upvotes]: 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)

REPLY [4 votes]: For what its worth, I can give you a non-Noetherian example, even with both schemes affine, irreducible (and of finite Krull dimension).
Set $R = k[x,y,x/y, x/y^2, x/y^3, ...]$ and $S = k[y]$.  We have the obvious map $S \hookrightarrow R$ which induces
$$
X = \text{Spec }R \to Y = \text{Spec }S.
$$
Now, away from the origin of $S$, $y$ is invertible and $R[y^{-1}] = k[x,y,y^{-1}]$ has all fibers with dimension $1$.  On the other hand, once we set $y = 0$ in $R$, we notice that $x = (x/y) y$ is a multiple, as is $(x/y) = (x/y^2) y$, and so is $(x/y^n)$ for all $n$.  This is already a maximal ideal, so the fiber over $y = 0$ is $0$-dimensional.