I'm confused about a basic point regarding the definition of the ring of regular functions on a closed subvariety. Let $X=\text{Spec}(A)$ be an affine variety (I'm thinking of varieties as integral, separated schemes of finite over an algebraically closed field but I don't think it matters here). Let $\mathfrak{p}$ be a prime ideal in A; we have a closed subscheme $Y=\text{Spec}(A/\mathfrak{p})\cong V(\mathfrak{p})\subset X$. Therefore the regular functions on $Y$ are the restrictions of regular functions on $X$, given by the quotient map $A\to A/\mathfrak{p}$. In particular I'm thinking about $A = \mathbb{C}[x,y]$, with $\mathfrak{p} = (f)$ for some irreducible polynomial $f$, so the regular functions on $V(f)$ are just polynomials in $x$ and $y$, identified if they agree on $V(f)$.
However, on an open set $U\subset X$, there are additional regular functions other than the restrictions of regular functions on $X$; in particular, we allow rational functions with poles outside $U$. For concreteness, let $h\in A$ be irreducible and suppose that $U=D(h)$, so we have the distinguished inclusion $U\cong \text{Spec}(A_h)\hookrightarrow \text{Spec}(A)$. The regular functions on $U$ then look like $\frac{g(x,y)}{h(x,y)^n}$ for $g\in A$ and $n\geq 0$.
Question: So what happens if $Y\subset U \subset X$? (That is, $V(f)\cap V(h)=\emptyset$.) Thinking of $Y$ as a closed subvariety of $U$, its regular functions are restrictions of regular functions on $U$ (and thus rational functions on $X$), so they are elements of $A_h/(f)$. It's not clear to me how to show in general (if it's even true!) that $A_h/(f)\cong A/(f)$, and so these are in fact the same scheme structure on $Y$.
I suspect that these should in fact be the same structure, and so any rational function like $\frac{g(x,y)}{h(x,y)^n}$ restricted to $V(f)$ should be the same as the restriction of some polynomial $q(x,y)$ to $V(f)$ (again, assuming that $h$ vanishes nowhere on $V(f)$). The only cases that I can come up in $\mathbb{A}_{\mathbb{C}}^2$ of two nonintersecting hypersurfaces are two parallel lines, and there it is clear that, if $f=0$ and $h=0$ define these lines, then $h$ is constant on $V(f)$ so these rational functions agree with polynomials. But I have no idea how one would deal with this in general cases where the intersections or lack thereof are much less obvious.
These two rings are in fact the same, so we can consider the subvariety $Y$ directly in $X$, or $Y$ in $U$ in $X$, and and the resulting structure sheaf is the same. Note that $h$ is already invertible in $A/(f)$: since $h$ doesn't vanish at any point of $V(f)$, this mean it isn't contained in any maximal ideal of $A/(f)$, so it must be a unit. Therefore $(A/(f))_h = A/(f)$. Now we use the fact that localization commutes with quotients, so $A_h/(f)\cong (A/(f))_h$. Putting these facts together, we have $A_h/(f)\cong A/(f)$. Therefore the regular functions are in fact the same.