All octane rating is, is the fuel's tendency to allow or resist igniting under compression. The higher the octane, the less "volitile" it is and wont ignite from compression and heat alone, it will need a spark to light it off. Ping or Knock is actually PREDETONATION where the fuel self ignites before the piston is in the proper timing BTDC. Fuel always ignites just a bit before the piston has reached TDC so that by time it's at TDC and into the combustion stroke the expansion is starting to take place and has time to make full use of the energy.
Some engines compress the fuel/air mix alot more than others, which makes the fuel ignite early, before the spark plug ignites it on proper timing. This causes the flame front and expansion to momentarily push really hard on the piston coming up still in it's compression stroke. Murder on conrods and main bearings.
Now, having said that, to get the MOST power and mileage from your engine, you run the lowest octane fuel you can without predetonation! Engines with knock sensors will re**** the timing, cooling the cylinders, which gets rid of alot of predetonation. These vehicles may see a loss in mileage in that instance. Ones without knock sensors, well, you'll hear it and know what you need to do. Move up a grade for a few tanks and listen, and if that fixes it, great, if not, move to premium. If premium doesnt fix it, you need to check deeper into the reason behind it. Be it carbon deposits raising your compression ratio, messed up vacuum advances, etc.
I run 87 in my 06 4.0 V6 and get about 19MPG out of it.
I run 93 in my 2000 Ram with some mods and an SCT tuner, and I have some mild detonation. I know the reason though, oil consumption leading to carbon deposits.