A relative clause is basically a sentence that modifies another sentence (almost like a sentence that works like an adjective).
Look at this sentence:
1. That was difficult.
Now look at this sentence:
2. I took a test.
I can use (1) to modify (2):
I took a test that was difficult.
Here I'm specifically talking about a difficult test--this is what we call a restrictive relative clause.
Some people say you should use that only with restrictive relative clauses but use which with non-restrictive relative clauses.
1. Bob gave me a shirt that had a hole in it. (restrictive)
2. Bob gave me a shirt, which was very generous. (non-restrictive)
In #1, it's a specific shirt that Bob gave me--the one with the hole in it! In #2, Bob gave a shirt, and I think it was very generous (the act of giving is generous--it's not a generous shirt).
So the rule goes you should use which whenever the relative clause does not restrict the noun it is modifying. I just read a blog post about the that/which rule. They used the first page of several great authors as evidence to support the idea that the that/which rule is not maintained by good writers.
I think "good writers" is too subjective. Let's look at more persnickety people. Sure, an author can have an air of arrogance, but what better place to look than published academic journal articles? Not only are they written by academics, but a team of academic editors scrutinize them heavily before they make it into print.
Using the COCA to look only at academic sources, we see the following uses of * which (* is any word):
But what about when we search for all instances of a noun before which? When I search for:
it gives me 31,585 results . What if I add in adjectives and adverbs?
So it looks like it's more common in academic writing to precede which with a comma, but not as uncommon to follow a noun with which and not use a comma (basically, the distinction that which is used ONLY for non-restrictive relative clauses doesn't seem to hold up).
Have a good one, and don't be scared by the bogeyman that says you always have to use a comma... unless they're handling your paycheck or grades!
 I had to increase the default frequency from 100 to 3000 because otherwise, it only shows me the top 100 nouns to precede which.
 I wanted to look for verbs, but it becomes more complicated since it's hard to separate the continuous -ING, and the gerund (noun form) -ING.