TITLE: Rings of integers of function fields
QUESTION [10 upvotes]: This might be a somewhat silly and inconsequential question, but it's aroused my curiosity. One has the theorem in commutative algebra that the integral closure of a domain $A$ in its field of fractions $Q(A)$ is the intersection of all the valuation subrings of $Q(A)$ containing $A$. This naturally leads to the impulse to define the ring of integers of an arbitrary field $k$, independent of any particular subring, to be the intersection of all valuation subrings of $k$. Really what one is doing here is taking the integral closure of the prime ring, which is to say the minimal integrally closed subring. This gives the answer one would expect for $\mathbb{Q}$ and for number fields. I believe that the ring of integers under this definition of $\mathbb{C}$ is $\overline{\mathbb{Z}}$, and the ring of integers of $\mathbb{R}$ is $\overline{\mathbb{Z}} \cap \mathbb{R}$. So far, so good.
Now here's the question: what happens in algebraic geometry? We could ask about the ring of integers $\mathcal{O}$ of the function field $Q(A)$ of an irreducible affine variety $\textbf{Spec
 }A$ over an algebraically closed field $k$, and naïvely hope that it coincides with $A$; but there may be many subalgebras of $Q(A)$ whose field of fractions is $Q(A)$, and at most one of these will be its ring of integers. Can we characterise geometrically those affine varieties whose coordinate ring is the ring of integers of its function field?
And what happens for function fields of more general varieties? For projective varieties, whose global ring of functions isn't much to write home about, we might hope for a more interesting answer.
Edit: It occurs to me that as it stands, the (boring) answer to my question is that the ring of integers is always inside the ground field. Let me instead ask the following, related question: for affine or general function fields $k(X)$, is it always true that there is a minimal (but not necessarily unique minimal) subring $R$ such that
$R$ is integrally closed in $k(X)$, and
$k(X)$ is algebraic over the field of fractions $Q(R)$?
If so, what is the geometric meaning of $R$, and when must we have $Q(R) = k(X)$?

REPLY [3 votes]: I understand this answer might be coming a little late, but the stack exchange "Related Questions" algorithm brought me here to a question that does not yet have a complete answer, so I'll answer it.
1) For such an $X,R$, $k(X)$ is indeed equal to $Q(R)$. The reason is that every element $\alpha$ of $k(X)$ is algebraic over $Q(R)$, and hence satisfies a monic polynomial equation with coefficients in $Q(R)$. If $f$ is the lcm of the denominators of the fractions appearing in the coefficients, then $f\alpha$ satisfies a monic polynomial equation with coefficients in $R$, and lies in $k(X)$, so by assumption lies in $R$, and $\alpha=\frac{f\alpha}{f}$ lies in $\mathbb Q(R)$.
2) As Felipe pointed out 7 years ago, if $X$ is a curve, then $R$ satisfies this condition if and only if it is the ring of functions on the complement of a closed point of $R$.
3) This cannot happen for a higher-dimensional variety. Let $Y = \operatorname{Spec} R$ and let $f$ be a nonconstant function on $Y$. Choose a projective compactification $\overline{Y}$ such that $f$ is well-defined: $\overline{Y} \to \mathbb P^1$. Then the divisor $\overline{Y}-Y$ is ample, and the zero locus of $f$ is effective, so because the dimension is at least $2$, they must have some nontrivial intersection. Blow this up, producing a compactification $\overline{Y}^*$ of $Y$ containing an exceptional divisor $E$ on which $f$ vanishes (because it is the blowup of a closed subscheme where $f$ vanishes).
Now consider the subring of $R$ consisting of all functions which do not have a pole at the generic point of $E$. Because it is the intersection of $R$ with a valuation ring, it is is integrally closed. Because $f$ vanishes at the generic point of $E$, we can for any element $g\in R$ there is some power $n$ such that $g f^n$ does not have a pole at the generic point of $E$, and so $g = \frac{ gf^n}{f^n}$ lies in $K(R)$. So the quotient ring of this subring is the quotient ring of $R$, which is the function field of $X$, as desired.
For the simplest example of this phenomenon, take $R= k[x,y]$, which is integrally closed in its field of fractions. Then the subring $k[x,xy]$ is integrally closed in the same field of fractions, and so on, ad infinitum, so none of these are minimal. By the geometric argument, we see that there is no minimal subring.