Let $i : U \to X$ be a quasicompact open immersion of schemes. I would like to know whether the canonical morphism $i\_\* \mathcal{O}\_U \otimes\_{\mathcal{O}\_X} i\_\* \mathcal{O}\_U \to i\_\* \mathcal{O}\_U$ is an isomorphism.


Remark that this is trivial if $i$ is an affine morphism (base change formula), so we're good with semi-separated $X$. But I don't know what happens in general. Of course we may assume that $X$ is affine. Then $U$ is a finite union of basic open subsets of $X$ and the question is equivalent to: Is the canonical map $\mathcal{O}(U) \otimes\_{\mathcal{O}(X)} \mathcal{O}(U) \to \mathcal{O}(U)$ an isomorphism?


In other words, is the restriction map $\mathcal{O}(X) \to \mathcal{O}(U)$ an epimorphism in the category of commutative rings? For example, if $U$ is basic open, then this is just a localization, thus an epimorphism. More generally, if $U$ is affine, it is an epimorphism (if you don't like the argument above) since the map on spectra is the open immersion $U \to X$, which is a monomorphism of schemes. For a simple positive example where $U$ is not affine, take $X=\mathbb{A}^2=\mathrm{Spec}(k[x,y])$ and $U = D(x) \cup D(y)$. Then the ring homomorphism is just the identity $k[x,y] \to k[x,y]$.


The best source for the theory of epimorphisms of commutative rings is: Séminaire Samuel. Algèbre commutative, 2, 1967-1968: Les épimorphismes d'anneaux, available on [nundam](http://www.numdam.org/numdam-bin/browse?id=SAC_1967-1968__2_). See also [this](https://mathoverflow.net/questions/109/what-do-epimorphisms-of-commutative-rings-look-like) mathoverflow discussion.


There are many characterizations of epimorphisms, but no one seems to answer the question directly.



Is the restriction map an epimorphism of commutative rings?
Martin, Mike is correct, $\Gamma(U)$ is indeed not free over $\Gamma(X)$, but most of what you are saying can be salvaged.


Here is what's happening:


Let $X=X\_1\cup X\_2$ be the union of the two copies of $\mathbb A^2$ glued at one point as you describe in your answer. Let $X'=X\_1\overset{\cdot}\cup X\_2$ the disjoint union of the two planes, i.e., $X'$ is the normalization of $X$. Since the normalization is $S\_2$ (see [here](https://mathoverflow.net/questions/45347/why-does-the-s2-property-of-a-ring-correspond-to-the-hartogs-phenomenon/45354#45354) for more on that) it follows that if $i':U\to X'$ is the embedding, then the natural map $\mathscr O\_{X'}\to i'\_\*\mathscr O\_U$ is isomorphic. In other words, 
$\Gamma(U, \mathscr O\_U)\simeq\Gamma(X',\mathscr O\_{X'})\simeq \Gamma(X\_1, \mathscr O\_{X\_1})\oplus\Gamma(X\_2, \mathscr O\_{X\_2})$ (this is the same as what you computed). 


However, the normalization map $X'\to X$ is an isomorphism outside of $\{p\}$, so this is not going to be free over $\mathscr O\_X$. In fact, as Mike suggests, $\mathscr O\_X\to i\_\*\mathscr O\_U$ is an isomorphism on $U$. Even **at** $\{p\}$ you do not get a rank two module over $\mathscr O\_X$. Localizing the above isomorphism of rings gives that $\left(i\_\*\mathscr O\_{U}\right)\_p\simeq \mathscr O\_{X\_1,p\_1}\oplus \mathscr O\_{X\_2,p\_2}$, but this is still not free over $\mathscr O\_{X,p}$! What's happening is that 
$$\mathscr O\_{X,p}=\{s\in \mathscr O\_{U,p} | s\_1(p)=s\_2(p) \}$$
where $s\_i(p)\in \mathscr O\_{X\_i,p\_i}\otimes \kappa(p\_i)$ is the value of the section $s$ at $p\_i$ evaluated on $X\_i$. 


So, to get the contradiction you want, you have to look at the residue fields at $p$, and then what you are saying is indeed true:
$\mathscr O\_{U,p}\otimes \kappa(p)$ is a $2$-dimensional vector space over $\mathscr O\_{X,p}\otimes \kappa(p)$ and hence $\mathscr O\_{U,p}\otimes\_{\mathscr O\_{X,p}} \mathscr O\_{U,p}\otimes \kappa(p)$ is a $4$-dimensional vector space over the same, so it follows that $i\_\*\mathscr O\_U\otimes\_{\mathscr O\_X}i\_\*\mathscr O\_U\to i\_\*\mathscr O\_U$ is not an isomorphism.


