About open subsets of affine schemes. Let $A$ be a commutative ring with unity. Consider its associated affine scheme $(\operatorname{Spec}(A),\mathcal{O}_A)$. I was wondering if the restriction morphism,
$$A \xrightarrow{r|^X_U} \mathcal{O}_A(U)$$
would induce an open immersion of $\operatorname{Spec}(\mathcal{O}_A(U))$ into $\operatorname{Spec}(A)$. I know this for the case of distinguished opens. What happens in the general case?
 A: Let me work out the counter example proposed in the comments.
Let $X = \operatorname{Spec}A$ be a non-normal isolated surface singularity, as constructed here: isolated non-normal surface singularity. Let $p$ be the singular point and $U = X \setminus \{p\}$ be the open complement. It turns out, that this will always be a counter example, and luckily we dont have to do any concrete computations.
Let $A \to \bar A$ be the integral closure (which is a finite extension, since $A$ is of finite type over a field), and $Y = \operatorname{Spec} \bar A \xrightarrow f X$ be the induced finite morphism of affine schemes. This induces an isomorphism over the normal locus, i.e. $Y \setminus f^{-1}(p) \xrightarrow{\sim} U$ .
Since the map is finite, we have that $f^{-1}(p)$ has codimension two in the normal scheme $Y$, hence by Hartog's lemma:
$$\mathcal O_X(U) = \mathcal O_U(U) = \mathcal O_{Y \setminus f^{-1}(p)}(Y \setminus f^{-1}(p)) = \mathcal O_Y(Y \setminus f^{-1}(p)) = \mathcal O_Y(Y) = \overline A$$
Hence you are asking whether the map $$A \to \mathcal O_X(U) = \overline A$$ induces an open immersion. Of course we expect the map to be the inclusion into the integral closure, thus the induced map is the map $f$. To show this rigorously, note that the sheaf map $\mathcal O_X \to f_* \mathcal O_Y$ gives rise to a commutative diagram
$$\require{AMScd}
\begin{CD}
A @>>> \overline A\\
@VVV @VV\operatorname{id}V \\
\mathcal O_X(U) @>\cong>> \mathcal O_Y(Y \setminus f^{-1}(p))=\overline A
\end{CD}$$
By functoriality of $\operatorname{Spec}$, we get a commutative diagram
$$\require{AMScd}
\begin{CD}
 Y @>\cong>> \operatorname{Spec} \mathcal O_X(U)\\
@V\operatorname{id}VV @VVV \\
Y @>f>> X
\end{CD}$$
Thus the map $\operatorname{Spec} \mathcal O_X(U) \to X$ is an open immersion if and only if $f$ is one. But $f$ is surjective and not an isomorphism, hence it can not be an open immersion.
