TITLE: Stalk of structure sheaf on fiber product of schemes
QUESTION [16 upvotes]: Let $X,Y$ be schemes, not necessary separated. Let $f:X\to Y$ be a morphism of schemes and $f(x)=y~,x\in X,~y\in Y$. Then we have the scheme theoretic fiber over $y$, i.e. $f^{-1}(y)=X\times_{Y} \text{Spec } \mathbb k(y)$ where $\mathbb k(y)$ is the residue field at $y$. I was told that $\mathcal O_{x,f^{-1}(y)}=\mathcal O_{x,X}\otimes_{\mathcal O_{y,Y}}\mathbb k(y)$. I can show this fact by writing down the rings involved explicitly and the proof only works for this special fiber product. I am now asking if there is a generalization, as follows.
Let $X,Y,Z$ be schemes, $f:X\to Z,~g:Y\to Z$ be morphisms of schemes, suppose that $w\in W=X\times_Z Y$ such that $w$ is sent to $x$, $y$ and $z$ in $X$, $Y$ and $Z$ respetively. Are $\mathcal O_{x,X}\otimes_{\mathcal O_{z,Z}} \mathcal O_{y,Y}$ and $\mathcal O_{w,W}$ naturally isomorphic? Note that there might be more than one $w$ over the pair of points $(x,y)$, they much have the same local rings if my guess is true.
I tried to prove this via commutative algebra. The question is local. Let $X,Y,Z$ be $\text{Spec } A,\text{Spec } B,\text{Spec } C$, respectively. Let $x,y,z,w$ correspond to prime ideals $P_1,P_2,Q,I$, respectively. Then I have to prove that $(A\otimes_C B)_I=A_{P_1}\otimes _{C_Q} B_{P_2}$. I want to check the universal property of tensor products. Given $\alpha:A_{P_1}\to E,\beta:B_{P_2}\to E$ such than they coincide when restricted to $C_{Q}$, we have a unique homomorphism $\gamma: A\otimes_C B\to E$. The only thing remaining to be checked is that $\gamma$ maps the complement of $I$ to units. And I am stuck here.
If my guess is true, would you help me finish my proof? Of course I will appreciate more if you give a better proof. If my guess is false, then what is the right conditions making it ture?

REPLY [15 votes]: Fiber products exist in the category of locally ringed spaces (see e.g. Gillam's paper), and this also provides a direct construction (without gluing!) of the fiber product of schemes and reveals its explicit structure as a locally ringed space.
If $f : X \to S$ and $g : Y \to S$ are morphisms of locally ringed spaces, then the fiber product $X \times_S Y$ has the following description: Elements are of the form $(x,y,s,\mathfrak{p})$, where $(x,y,s)$ lies in the underlying topological fiber product, i.e. $x \in X$, $y \in Y$ with $f(x)=s=g(y)$, and $\mathfrak{p} \subseteq \mathcal{O}_{X,x} \otimes_{\mathcal{O}_{S,s}} \mathcal{O}_{Y,y}$ is a prime ideal satisfying $\mathfrak{p} \cap \mathcal{O}_{X,x} = \mathfrak{m}_x$ and $\mathfrak{p} \cap \mathcal{O}_{Y,y} = \mathcal{m}_y$. The stalk of the structure sheaf at such a point is the localization $(\mathcal{O}_{X,x} \otimes_{\mathcal{O}_{S,s}} \mathcal{O}_{Y,y})_{\mathfrak{p}}$. As for the topology and the structure sheaf in general, one uses (as in the construction of affine schemes) localization at elements $f \notin \mathfrak{p}$.
Actually, all this can be derived from the universal property of local schemes and the universal property of fiber products (exercise).