When the state district attorneys office sends a young lawyer to Mayberry for law enforcement training Barney immediately becomes suspicious. When Bob Rogers turns out to be a competent deputy Barney becomes convinced that Bob is out to get his job. A day or so later Barney turns in his resignation as Andy's deputy believing he is doing the right thing by stepping aside for the new and better man.
The only problem is that Bob was never intended to be Barney's replacement and was only working at the Mayberry's Sheriff's Department temporarily. Nonetheless, Barney embarks upon a new career as a door to door vacuum cleaner salesman.
Unfortunately, Barney is less of a salesman than he was a deputy. When Andy runs into Barney on the street, toting his vacuum cleaner, he discovered that despite a week of legwork Barney has not made a single sale. He tried to convince Barney to come back to work as a deputy but Barney, ever prideful and refusing to admit he's a failure as a salesman, refuses.
Back at the jail Bob Rogers is doing a stellar job, as usual, so perfect that he's starting to get on Andy's nerves. Bob mentions to Andy that he suspects Barney is selling door to door without a license. When Andy explains that Barney doesn't need a license, Bob reminds Andy of the Green River Ordinance. Seeing an opportunity to set things straight, Andy sends Bob out to pick Barney up.
Bob drags Barney and his vacuum into the jail a little while later. When Bob is explaining to Andy and Barney this statistically it was only a matter of time before someone violated the ordinance Barney gets enough, lets himself out of jail, gives Bob a lecture on treating people as people and not statistics and straps on his old gun belt and rejoins the force.